Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi every on
How can i get all created objects in my application after i create it ?.....
not: i do't know the names of created objects, the thing is i need for all objects i was created
Posted
Updated 4-Dec-11 14:52pm
v2
Comments
Sergey Alexandrovich Kryukov 4-Dec-11 21:39pm    
Did you ever had references to any of those objects?
--SA
tarekwarak0 4-Dec-11 21:42pm    
yes, because i do't have names of objs

1 solution

There is no such thing. When you go out of some context so you loose the references to some reference objects, the objects are considered as logically nonexistent. As .NET uses garbage-collected (managed) memory, these objects will be scheduled for destruction and their allocated memory will be eventually reclaimed. This is called reachability, which is a non-trivial concept. The object is protected from destruction as soon as it is reachable. It does not have to have a name. An object can be reachable as a member of array, collection or any other container. You are the one who is responsible for keeping the references, as a developer.

Please see http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29#Reachability_of_an_object[^].

An object can be referenced using a weak reference which does not prevent a garbage collector (GC) to collect referenced objects having no regular (non-weak) references. See:
http://en.wikipedia.org/wiki/Weak_reference[^].
http://msdn.microsoft.com/en-us/library/system.weakreference.aspx[^].

By the way, in the systems without garbage collection, there is also no access the heap objects not reachable from the application code. In such systems is simply leads to memory leaks. The developer is responsible for keeping track of all objects created on heap. For example, in C++ one can override the "new" operator and collect pointers to the allocated memory, but usually the deletion of objects is done at the exit from some scope.

You really need to understand such things if you want to do software development.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900