Hi there,

Am 01.12.2008 um 14:50 schrieb Matthew Gregory:

> You could use "delete this.array" to free the memory instantly, it is
> much slower than assigning it to null and waiting for the GC though.

Sorry, but I don't think this is true. "delete this.array" simply  
removes the "array" key from the associative array that is referenced  
by "this". It doesn't really "delete" it (as there may be other  
references to the object), and it's certainly not slower than  
assigning it to null. (I suppose you didn't really test the  
performance of "delete". If you did, I'd be interested in the results.)

More comments below.

> Jean-Baptiste BRIAUD -- Novlog wrote:
>> Hi,
>>
>> I'm using at several places what I called an associative array :
>> this.array[key] = value;
>>
>> I would like to be sure I release memory used by the array. Would you
>> advice me to rely on garbage collector or should I do something
>> special ?

In general, the browser GC cleans up any unreferenced object.  
Unfortunately, there's one big exception: The GC of Microsoft's  
Internet Explorer cannot cope with cyclic references between "pure"  
JavaScript objects and DOM objects. Take a look at this code snippet:

var domObject = document.createElement("div");
var jsObject = new Object();
domObject.pointerToJS = jsObject;
jsObject.pointerToDOM = domObject;

Here you have a cyclic dependency between the div element and  
jsObject. There are also much more subtle ways that can lead to such a  
dependency (including closures).

The big problem is that IE doesn't free the memory of such cycles -  
ever! Not even when you leave the current page. (At least this is true  
for IE up to version 7 - don't know about 8.)

>> Various solution :
>> 1. this.array = null; // Is is enought ?

This is enough if you don't store any DOM references (directly or  
indirectly) in the array. The "array" key itself is still held in  
memory (a simple string). If you want to get rid of it, use "delete  
this.array", but that's not necessary if you reuse the same key later  
on.

>> 2. Browse the array and apply for each member array[i] = null; then  
>> do
>> 1.

Not necessary (except to clean up DOM references).

>> 3. Something else ?

As long as no DOM references are involved, you don't even need to set  
this.array to null. If the object referenced by "this" falls out of  
scope and isn't referenced from anywhere anymore, it's cleaned up  
automatically (including the array property).

Regards,

   Andreas


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to