473,542 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3020
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
1866
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 to be perfect. For example, I'd be happy with something where there was at most one pause per second, each pause was less than .2 seconds, and half...
6
810
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
1731
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 stock ticker using the managed DirectX libraries and the animation needs to be perfectly smooth. Problem is that the garbage collector will kick in...
11
2714
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 this? Is it because C is generally a 'low level' language and they didn't want garbage collection to creep into C++ and ruin everything? Just...
34
6363
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, probably a few hundred lines of code in Python. There is a need to interact with network using the socket module, and then probably a need to do...
55
4091
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) (a=NULL) NICE isn't it?
5
3571
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 measurement exactly 10 ms apart. In the future this may decrease to 5ms ). I am concerned that if garbage collection invokes during this time it may...
28
3136
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 this work be library based or language based and will it be based on that of managed C++? Then of course there are the finer technical questions...
158
7708
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 discouraged due to some specific reason. If someone can give inputs on the same, it will be of great help. Regards, Pushpa
0
7330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7571
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7721
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7324
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3376
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1798
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.