dcsimg
dynamic memory and GC.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Lior_Cohen
Posted On:   Monday, March 25, 2002 03:58 AM

Hi, I have bad memory problems and I would like to know what is the proper way to handle the following scenario (The object that will be created will be called Obj1and each time before using this object I need to call his constructor ): 1.a. There is a global declaration in main class Obj1 ObjectItem; b. When I want to use ObjectItem I do: ObjectItem = new Obj1(); c. When I finished working with ObjectItem object: ObjectItem = null; My question is: 1.1 Is the GC will perform the cleanup of ObjectItem object ? 1.2 What will happened if before the GC activation    More>>

Hi,
I have bad memory problems and I
would like to know what is the proper
way to handle the following scenario
(The object that will be created will
be called Obj1and each time before
using this object I need to
call his constructor ):

1.a. There is a global declaration in
main class

Obj1 ObjectItem;

b. When I want to use ObjectItem I
do:

ObjectItem = new Obj1();

c. When I finished working with
ObjectItem object:

ObjectItem = null;

My question is:

1.1 Is the GC will perform the cleanup
of ObjectItem object ?
1.2 What will happened if before the
GC activation There will be another
use in this object and we call the
constructor again ? will the old
object memory will be free ?
1.3 What will happened if I will not
write null in object ?
Is every constructor call will
increase the memory usage even
though we have only one object?
1.4 Will there be any problems if the
object is declared in local
procedure.

Thanks a lot,
Lior Cohen.

   <<Less

Re: dynamic memory and GC.

Posted By:   Dermot_Hennessy  
Posted On:   Tuesday, March 26, 2002 08:09 PM

Generally - you seem to require a singleton object. Please reference a patterns book or website for more details.

1.1 It will, if it gets to run. The GC thread is low priority, and will not get to run if your threading model does not permit it.

1.2 Should be answered by the "Generally" answer above.

1.3 The purpose behind telling that GC thread that an object is null is to explicitly mark that object for GC. It may be GC'ed anyway - that depends on the number of references held to that object in "live" memory.

1.4 The singleton pattern (and a proper understanding thereof) should again answer this question.

Hope this helps

Dermot

About | Sitemap | Contact