Object Creation and Dispoing 
Author Message
 Object Creation and Dispoing

This is .Net

Should an object be disposed as soon as I get what i need from it? Obvously
unless I need
to keep it alive for some other actions against it.

Such as a class that contains tons of functions... As the app opens the
functions needed
to display some information are grabbed from the newly dimmed object, then
should I
dispose the object?



Sat, 29 Jan 2005 07:03:35 GMT  
 Object Creation and Dispoing
I think you don't need to take care of this, just leave it to Garbage
Collector (GC) in .NET. The .NET Framework's garbage collector manages the
allocation and release of memory for your application. Each time you use
the new operator to create an object, the runtime allocates memory for the
object from the managed heap. As long as address space is available in the
managed heap, the runtime continues to allocate space for new objects.
However, memory is not infinite. Eventually the garbage collector must
perform a collection in order to free some memory. The garbage collector's
optimizing engine determines the best time to perform a collection, based
upon the allocations being made. When the garbage collector performs a
collection, it checks for objects in the managed heap that are no longer
being used by the application and performs the necessary operations to
reclaim their memory.

Luke

(This posting is provided "AS IS", with no warranties, and confers no
rights.)



Sat, 29 Jan 2005 11:16:51 GMT  
 Object Creation and Dispoing
Luke is correct. Leave it to the garbage collector. The only time you should
really be concerned with disposing  of things is when your using un-managed
resources such as files or database connections.

Lou



Quote:
> I think you don't need to take care of this, just leave it to Garbage
> Collector (GC) in .NET. The .NET Framework's garbage collector manages the
> allocation and release of memory for your application. Each time you use
> the new operator to create an object, the runtime allocates memory for the
> object from the managed heap. As long as address space is available in the
> managed heap, the runtime continues to allocate space for new objects.
> However, memory is not infinite. Eventually the garbage collector must
> perform a collection in order to free some memory. The garbage collector's
> optimizing engine determines the best time to perform a collection, based
> upon the allocations being made. When the garbage collector performs a
> collection, it checks for objects in the managed heap that are no longer
> being used by the application and performs the necessary operations to
> reclaim their memory.

> Luke

> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)



Sat, 29 Jan 2005 12:09:29 GMT  
 Object Creation and Dispoing
If your object contains so-called unmanaged resources (note that .net only
'manages' memory) then you should free them up explicitly, unless you don't
mind that these resources will hang around for an indeterminate time.

ie. If your object contains nothing but other objects, types and similar,
and these don't contain any expensive resources, then just set it to null
and forget about it. the object's memory will be cleaned up for you
eventually.

if, however, your object contains a database connection (for example), then
you really should close the connection ehwn you've finished with your object
(preferably via dispose call). The dispose call will not clean up the memory
allocated for the object - only the resources you tell it to clean up.
Eventually the object's memory will be cleaned up by the GC just like in the
previous example.

so.. ignore memory, keep a very firm track of everything else.

Cheers, Andy.



Sat, 29 Jan 2005 18:30:41 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. object creation and destruction?

2. ActiveX object creation on an ASP page

3. Licensed ActiveX object creation using createElement problem.

4. Run time object creation

5. dynamic object creation in VB4

6. Dynamic Creation of Object Names - Forms

7. object creation

8. Object creation

9. Creation of new objects (stupid question)

10. Object creation error

11. Object creation & Job queue suggestions

12. Dynamic creation of ole object

 

 
Powered by phpBB® Forum Software