PDA

View Full Version : Resource management clarifications.



elihorn
September 3rd, 2008, 06:07 PM
Hello again, I feel like I'm posting quite often lately...
I am just finishing up a major site and am trying to make sure it is optimized properly. I have been reading a lot of posts on resource management, including articles by gskinner and senocular about the garbage collector and everything, so I have an idea of what I need to do, but I just want to clarify a few things:

1. Removing an object from the display list and setting it to null will mark it for collection? Or does every reference to that object also need to be removed. And is using 'object=null' the best way?

2. When an object gets collected does this remove all its children as well, or does each child need to be removed individually?

3. Do you need to remove all stored data in an instance (ie. arrays and objects storing reference variables, external data, etc). Or will this be removed with an instance?

4. I read that reusing objects is a good way to conserve memory, so does replacing one instance of a class with another actually remove the original one? For example:


object = new classInstance1();
object = new classInstance2();
Does this mean classInstance1 no longer exists, or is ready for collection?

Right now I'm just setting cleanUp() functions within display classes that get called before an instance is removed, removing and nulling all children, removing any remaining event listeners, etc. but I haven't seen any examples of resource management in actual use, so is this a valid way to do it?

Sorry if these are stupid questions, I'm just trying to wrap my head around this whole process. Thanks in advance!

sekasi
September 3rd, 2008, 06:57 PM
1. Every reference needs to go. Including listeners. Nulling references is quite alright.

2. I'm still not quite sure of this since there definitely seems to be instances where a class gets GC'ed and in the process orphans a lot of data that that class held. This is a very sketchy question as well since System memory checks don't quite add up and the ugly GC collect hack seems unreliable as well. If anything I would like a clarification from someone like Senocular on this one. The main issue (for me at least) seems to arise when you prepare a class for garbage collection and that class has a lot of internal data still active (Arrays, objects, loaders, whatnot). Seems that data is still held on to.. somewhere in space with David Bowie :x

3. No, when you null an array it should not orphan your data. Had a long discussion with Anogar about this one just a few days ago and I think the mutual conclusion through testing was that it doesn't orphan anything, regardless.

4. classInstance1 is ready for GC in that example, provided it has no listeners, references or exists on the display list.

GL :)