473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Garbage collection

For some reason it appears that garbage collection is releasing an object
that I'm still using. The object is declared in a module and instantiated
within a class that is in turn instantiated by the mainline. The class that
instantiated the object in question is definitely still in existence at the
point garbage collection swoops in and yanks it out from under my processing.
Is there a way to ensure an instantiated object cannot be freed by garbage
collection until I want it to? Also, if there is a definitive description of
the rules of garbage collection that you could direct me to, that would be
appreciated. Thanks for any help.

-Mike

Dec 8 '05 #1
8 2996
What makes you think that garbage collection is getting rid of the object?
Or that it is even running whent his happens?

This is the first I've heard of this kind of thing. If anything, the
opposite is usually the problem. I tend to think there is something else
going on.

"mike2036" <mi******@discussions.microsoft.com> wrote in message
news:D8**********************************@microsof t.com...
For some reason it appears that garbage collection is releasing an object
that I'm still using. The object is declared in a module and instantiated
within a class that is in turn instantiated by the mainline. The class
that
instantiated the object in question is definitely still in existence at
the
point garbage collection swoops in and yanks it out from under my
processing.
Is there a way to ensure an instantiated object cannot be freed by garbage
collection until I want it to? Also, if there is a definitive description
of
the rules of garbage collection that you could direct me to, that would be
appreciated. Thanks for any help.

-Mike

Dec 8 '05 #2
Hi Marina,

Let me illustrate the situation a little better:

---------------------------------

Module MyModule

....

Public MyObjectA As MyObjectTypeA
Public MyObjectB As MyObjectTypeB

....

Public Sub Main()

Dim MyObjectC As New MyObjectTypeC

Debug.WriteLine("Main:About to initialize ObjC")
MyObjectC.Initialize()

Debug.WriteLine("Main:About to Process ObjB")
MyObjectB.Process()

Debug.WriteLine("Main:About to go into message loop")
Application.Run()

End Sub

-----------------------------------

Class MyObjectTypeC

....

Public Sub Initialize

Debug.WriteLine("ObjC_Init:About to instantiate ObjB")
MyObjectB = New MyObjectTypeB

End Sub

------------------------------------

Class MyObjectTypeB

....

Public Sub Process

Debug.WriteLine("ObjB_Process:About to instantiate ObjA")
MyObjectA = New MyObjectTypeA

End Sub

------------------------------------

WndProc

....

If e.Msg = TYPE_A_PROCESS_MSG
Debug.WriteLine("WndProc:About to process Obj A msg")
MyObjectA.ProcessMsg()
End If

------------------------------------

Class MyObjectTypeA

....

Public Sub Finalize()

Debug.WriteLine("ObjA:Garbage collection cleaning me up!")

End Sub
Public Sub ProcessMsg()

Debug.WriteLine("ObjA:About to do stuff")
DoStuff()
Debug.WriteLine("ObjA:About to force GC")
GC.Collect()
Application.DoEvents()

End Sub

------------------------------------

This would be the output based on the above:

Main:About to initialize ObjC
ObjC_Init:About to instantiate ObjB
Main:About to process ObjB
ObjB_Process:About to instantiate ObjA
Main:About to go into Message loop
....
[Somebody sends us a TYPE_A_PROCESS_MSG]
WndProc:About to process Obj A msg
ObjA:About to do stuff
ObjA:About to force GC
ObjA:Garbage collection cleaning me up!

-------------------------------------

That's what's happening. For some reason, GC thinks Object A has no
references. I'm baffled.

-Mike
"Marina" wrote:
What makes you think that garbage collection is getting rid of the object?
Or that it is even running whent his happens?

This is the first I've heard of this kind of thing. If anything, the
opposite is usually the problem. I tend to think there is something else
going on.

"mike2036" <mi******@discussions.microsoft.com> wrote in message
news:D8**********************************@microsof t.com...
For some reason it appears that garbage collection is releasing an object
that I'm still using. The object is declared in a module and instantiated
within a class that is in turn instantiated by the mainline. The class
that
instantiated the object in question is definitely still in existence at
the
point garbage collection swoops in and yanks it out from under my
processing.
Is there a way to ensure an instantiated object cannot be freed by garbage
collection until I want it to? Also, if there is a definitive description
of
the rules of garbage collection that you could direct me to, that would be
appreciated. Thanks for any help.

-Mike


Dec 8 '05 #3
Are you trying to say that object A forces its own garbage collection?
That's what it seems you are trying to say.

Also, if you run this twice, the second time MyObjectA.ProcessMsg() is
called, is there an error?

Also, I am not sure why you are trying to force garbage collection? Why not
let it happen when deemed necessary by the run time?

"mike2036" <mi******@discussions.microsoft.com> wrote in message
news:96**********************************@microsof t.com...
Hi Marina,

Let me illustrate the situation a little better:

---------------------------------

Module MyModule

...

Public MyObjectA As MyObjectTypeA
Public MyObjectB As MyObjectTypeB

...

Public Sub Main()

Dim MyObjectC As New MyObjectTypeC

Debug.WriteLine("Main:About to initialize ObjC")
MyObjectC.Initialize()

Debug.WriteLine("Main:About to Process ObjB")
MyObjectB.Process()

Debug.WriteLine("Main:About to go into message loop")
Application.Run()

End Sub

-----------------------------------

Class MyObjectTypeC

...

Public Sub Initialize

Debug.WriteLine("ObjC_Init:About to instantiate ObjB")
MyObjectB = New MyObjectTypeB

End Sub

------------------------------------

Class MyObjectTypeB

...

Public Sub Process

Debug.WriteLine("ObjB_Process:About to instantiate ObjA")
MyObjectA = New MyObjectTypeA

End Sub

------------------------------------

WndProc

...

If e.Msg = TYPE_A_PROCESS_MSG
Debug.WriteLine("WndProc:About to process Obj A msg")
MyObjectA.ProcessMsg()
End If

------------------------------------

Class MyObjectTypeA

...

Public Sub Finalize()

Debug.WriteLine("ObjA:Garbage collection cleaning me up!")

End Sub
Public Sub ProcessMsg()

Debug.WriteLine("ObjA:About to do stuff")
DoStuff()
Debug.WriteLine("ObjA:About to force GC")
GC.Collect()
Application.DoEvents()

End Sub

------------------------------------

This would be the output based on the above:

Main:About to initialize ObjC
ObjC_Init:About to instantiate ObjB
Main:About to process ObjB
ObjB_Process:About to instantiate ObjA
Main:About to go into Message loop
...
[Somebody sends us a TYPE_A_PROCESS_MSG]
WndProc:About to process Obj A msg
ObjA:About to do stuff
ObjA:About to force GC
ObjA:Garbage collection cleaning me up!

-------------------------------------

That's what's happening. For some reason, GC thinks Object A has no
references. I'm baffled.

-Mike
"Marina" wrote:
What makes you think that garbage collection is getting rid of the
object?
Or that it is even running whent his happens?

This is the first I've heard of this kind of thing. If anything, the
opposite is usually the problem. I tend to think there is something else
going on.

"mike2036" <mi******@discussions.microsoft.com> wrote in message
news:D8**********************************@microsof t.com...
> For some reason it appears that garbage collection is releasing an
> object
> that I'm still using. The object is declared in a module and
> instantiated
> within a class that is in turn instantiated by the mainline. The class
> that
> instantiated the object in question is definitely still in existence at
> the
> point garbage collection swoops in and yanks it out from under my
> processing.
> Is there a way to ensure an instantiated object cannot be freed by
> garbage
> collection until I want it to? Also, if there is a definitive
> description
> of
> the rules of garbage collection that you could direct me to, that would
> be
> appreciated. Thanks for any help.
>
> -Mike
>


Dec 8 '05 #4
I force garbage collection as a test, not as a normal activity. Without it
it still happens, but as an automated occurence and therefore not
consistently. When I force garbage collection, it happens every time.

"Marina" wrote:
Are you trying to say that object A forces its own garbage collection?
That's what it seems you are trying to say.

Also, if you run this twice, the second time MyObjectA.ProcessMsg() is
called, is there an error?

Also, I am not sure why you are trying to force garbage collection? Why not
let it happen when deemed necessary by the run time?

"mike2036" <mi******@discussions.microsoft.com> wrote in message
news:96**********************************@microsof t.com...
Hi Marina,

Let me illustrate the situation a little better:

---------------------------------

Module MyModule

...

Public MyObjectA As MyObjectTypeA
Public MyObjectB As MyObjectTypeB

...

Public Sub Main()

Dim MyObjectC As New MyObjectTypeC

Debug.WriteLine("Main:About to initialize ObjC")
MyObjectC.Initialize()

Debug.WriteLine("Main:About to Process ObjB")
MyObjectB.Process()

Debug.WriteLine("Main:About to go into message loop")
Application.Run()

End Sub

-----------------------------------

Class MyObjectTypeC

...

Public Sub Initialize

Debug.WriteLine("ObjC_Init:About to instantiate ObjB")
MyObjectB = New MyObjectTypeB

End Sub

------------------------------------

Class MyObjectTypeB

...

Public Sub Process

Debug.WriteLine("ObjB_Process:About to instantiate ObjA")
MyObjectA = New MyObjectTypeA

End Sub

------------------------------------

WndProc

...

If e.Msg = TYPE_A_PROCESS_MSG
Debug.WriteLine("WndProc:About to process Obj A msg")
MyObjectA.ProcessMsg()
End If

------------------------------------

Class MyObjectTypeA

...

Public Sub Finalize()

Debug.WriteLine("ObjA:Garbage collection cleaning me up!")

End Sub
Public Sub ProcessMsg()

Debug.WriteLine("ObjA:About to do stuff")
DoStuff()
Debug.WriteLine("ObjA:About to force GC")
GC.Collect()
Application.DoEvents()

End Sub

------------------------------------

This would be the output based on the above:

Main:About to initialize ObjC
ObjC_Init:About to instantiate ObjB
Main:About to process ObjB
ObjB_Process:About to instantiate ObjA
Main:About to go into Message loop
...
[Somebody sends us a TYPE_A_PROCESS_MSG]
WndProc:About to process Obj A msg
ObjA:About to do stuff
ObjA:About to force GC
ObjA:Garbage collection cleaning me up!

-------------------------------------

That's what's happening. For some reason, GC thinks Object A has no
references. I'm baffled.

-Mike
"Marina" wrote:
What makes you think that garbage collection is getting rid of the
object?
Or that it is even running whent his happens?

This is the first I've heard of this kind of thing. If anything, the
opposite is usually the problem. I tend to think there is something else
going on.

"mike2036" <mi******@discussions.microsoft.com> wrote in message
news:D8**********************************@microsof t.com...
> For some reason it appears that garbage collection is releasing an
> object
> that I'm still using. The object is declared in a module and
> instantiated
> within a class that is in turn instantiated by the mainline. The class
> that
> instantiated the object in question is definitely still in existence at
> the
> point garbage collection swoops in and yanks it out from under my
> processing.
> Is there a way to ensure an instantiated object cannot be freed by
> garbage
> collection until I want it to? Also, if there is a definitive
> description
> of
> the rules of garbage collection that you could direct me to, that would
> be
> appreciated. Thanks for any help.
>
> -Mike
>


Dec 8 '05 #5
What does "DoStuff" do? Does it interact with any of the A, B, or C
objects?

Dec 8 '05 #6
Hi Chris,

DoStuff() does not interact with any of the other objects.

"Chris Dunaway" wrote:
What does "DoStuff" do? Does it interact with any of the A, B, or C
objects?

Dec 8 '05 #7
Mike,

Can you post a short, but complete program that demonstrates the
problem?

Brian

mike2036 wrote:
Hi Marina,

Let me illustrate the situation a little better:

---------------------------------

Module MyModule

...

Public MyObjectA As MyObjectTypeA
Public MyObjectB As MyObjectTypeB

...

Public Sub Main()

Dim MyObjectC As New MyObjectTypeC

Debug.WriteLine("Main:About to initialize ObjC")
MyObjectC.Initialize()

Debug.WriteLine("Main:About to Process ObjB")
MyObjectB.Process()

Debug.WriteLine("Main:About to go into message loop")
Application.Run()

End Sub

-----------------------------------

Class MyObjectTypeC

...

Public Sub Initialize

Debug.WriteLine("ObjC_Init:About to instantiate ObjB")
MyObjectB = New MyObjectTypeB

End Sub

------------------------------------

Class MyObjectTypeB

...

Public Sub Process

Debug.WriteLine("ObjB_Process:About to instantiate ObjA")
MyObjectA = New MyObjectTypeA

End Sub

------------------------------------

WndProc

...

If e.Msg = TYPE_A_PROCESS_MSG
Debug.WriteLine("WndProc:About to process Obj A msg")
MyObjectA.ProcessMsg()
End If

------------------------------------

Class MyObjectTypeA

...

Public Sub Finalize()

Debug.WriteLine("ObjA:Garbage collection cleaning me up!")

End Sub
Public Sub ProcessMsg()

Debug.WriteLine("ObjA:About to do stuff")
DoStuff()
Debug.WriteLine("ObjA:About to force GC")
GC.Collect()
Application.DoEvents()

End Sub

------------------------------------

This would be the output based on the above:

Main:About to initialize ObjC
ObjC_Init:About to instantiate ObjB
Main:About to process ObjB
ObjB_Process:About to instantiate ObjA
Main:About to go into Message loop
...
[Somebody sends us a TYPE_A_PROCESS_MSG]
WndProc:About to process Obj A msg
ObjA:About to do stuff
ObjA:About to force GC
ObjA:Garbage collection cleaning me up!

-------------------------------------

That's what's happening. For some reason, GC thinks Object A has no
references. I'm baffled.

-Mike


Dec 8 '05 #8
Hi Brian,

I did build an applet to attempt to recreate the problem but have been
unsuccessful. In my "DoStuff()" routine I interface with one of our DLL's,
and I suspect it's messing with memory or doing something it shouldn't be,
which is triggering Garbage Collection.

"Brian Gideon" wrote:
Mike,

Can you post a short, but complete program that demonstrates the
problem?

Brian

mike2036 wrote:
Hi Marina,

Let me illustrate the situation a little better:

---------------------------------

Module MyModule

...

Public MyObjectA As MyObjectTypeA
Public MyObjectB As MyObjectTypeB

...

Public Sub Main()

Dim MyObjectC As New MyObjectTypeC

Debug.WriteLine("Main:About to initialize ObjC")
MyObjectC.Initialize()

Debug.WriteLine("Main:About to Process ObjB")
MyObjectB.Process()

Debug.WriteLine("Main:About to go into message loop")
Application.Run()

End Sub

-----------------------------------

Class MyObjectTypeC

...

Public Sub Initialize

Debug.WriteLine("ObjC_Init:About to instantiate ObjB")
MyObjectB = New MyObjectTypeB

End Sub

------------------------------------

Class MyObjectTypeB

...

Public Sub Process

Debug.WriteLine("ObjB_Process:About to instantiate ObjA")
MyObjectA = New MyObjectTypeA

End Sub

------------------------------------

WndProc

...

If e.Msg = TYPE_A_PROCESS_MSG
Debug.WriteLine("WndProc:About to process Obj A msg")
MyObjectA.ProcessMsg()
End If

------------------------------------

Class MyObjectTypeA

...

Public Sub Finalize()

Debug.WriteLine("ObjA:Garbage collection cleaning me up!")

End Sub
Public Sub ProcessMsg()

Debug.WriteLine("ObjA:About to do stuff")
DoStuff()
Debug.WriteLine("ObjA:About to force GC")
GC.Collect()
Application.DoEvents()

End Sub

------------------------------------

This would be the output based on the above:

Main:About to initialize ObjC
ObjC_Init:About to instantiate ObjB
Main:About to process ObjB
ObjB_Process:About to instantiate ObjA
Main:About to go into Message loop
...
[Somebody sends us a TYPE_A_PROCESS_MSG]
WndProc:About to process Obj A msg
ObjA:About to do stuff
ObjA:About to force GC
ObjA:Garbage collection cleaning me up!

-------------------------------------

That's what's happening. For some reason, GC thinks Object A has no
references. I'm baffled.

-Mike


Dec 9 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andrew | last post by:
When will .NET have a low-pause-time garbage collector A low-pause-time garbage collector would greatly improve .NET's ability to serve as a platform for soft real-time systems. It doesn't have...
6
by: Ganesh | last post by:
Is there a utility by microsoft (or anyone) to force garbage collection in a process without have access to the process code. regards Ganesh
2
by: Oculus | last post by:
Before I get into the question -- I know .NET isn't the right solution for this app but it's part of my clients requirements and writing this in C++ isn't an option. That being said -- my app is a...
11
by: Rick | last post by:
Hi, My question is.. if Lisp, a 40 year old language supports garbage collection, why didn't the authors of C++ choose garbage collection for this language? Are there fundamental reasons behind...
34
by: Ville Voipio | last post by:
I would need to make some high-reliability software running on Linux in an embedded system. Performance (or lack of it) is not an issue, reliability is. The piece of software is rather simple,...
55
by: jacob navia | last post by:
Tired of chasing free(tm) bugs? Get serious about C and use lcc-win32. The garbage collector designed by Boehm is the best of its class. Very simple: #define malloc GC_malloc #define free(a)...
5
by: Bob lazarchik | last post by:
Hello: We are considering developing a time critical system in C#. Our tool used in Semiconductor production and we need to be able to take meaurements at precise 10.0 ms intervals( 1000...
28
by: Goalie_Ca | last post by:
I have been reading (or at least googling) about the potential addition of optional garbage collection to C++0x. There are numerous myths and whatnot with very little detailed information. Will...
158
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.