11-24-2010 05:35 AM
I have multiple screens in my application and each screen has few custom controls and bitmap images.
When I move from one screen to an another screen, I do not need old screen anymore. What is the best way to completely dispose the pervious screen? I would also like to dispose all objects created by that screen as well.
I had a deep look into the forums and books but I cannot find or think of any good solution.
Your help will be very much appriciated.
Solved! Go to Solution.
11-24-2010 05:58 AM
Thank you Aman,
My main concern is memory usage.
Even if I set the previous screen to null, the screen object does not release the memory. When I see the object viewer, I could see all previous screens and their controls still occupying memory.
Is that any idea how can I release memory here? Just FYI, I ran the GC to check if it removed the main object.
11-24-2010 06:46 AM
11-24-2010 07:21 AM
That's what I have been doing - popScreen and discarding all references (setting them to null).
But when I debug, the discarded objects are still appearing in the object viewer. I am not sure if something wrong with the Object Viewer?
11-24-2010 07:43 AM
11-24-2010 07:52 AM - edited 11-24-2010 07:53 AM
I am aware of the fact that GC runs when he wants! but there is a button to run GC manually from the Object View window. I ran it manually to check if the objects are being removed. But unfortunately not.
Now just to make sure - if I set the object to null, will all the references to that object be removed automatically?
11-24-2010 02:34 PM
Setting an object to null is not the same as removing all references - setting a reference to null only removes that one reference.
For example, if you create a Field, add it to a manager, then null the reference to the Field, then your code no longer references the Field. However the Field is still referenced by the Manager.