Garbage Collection

Hi,
I've got a script that consumes a lot of memory, and I specifically need to remove objects that I don't use anymore. I doesn't seem as if

myObject = null;

works very well. Is there anyway you can release resources?

Thanks on advance,
Nille

Comments

  • : Hi,
    : I've got a script that consumes a lot of memory, and I specifically need to remove objects that I don't use anymore. I doesn't seem as if
    :
    : myObject = null;
    :
    : works very well. Is there anyway you can release resources?
    :
    : Thanks on advance,
    : Nille
    :

    Hi there,

    The DELETE method will destroy any object that is created. Here is an excerp from the JS Documentation...

    [code]

    delete
    The delete operator deletes an object, an object's property, or an element at a specified index in an array.Implemented in
    JavaScript 1.2, NES 3.0

    ECMA version
    ECMA-262

    Syntax
    delete objectNamedelete objectName.propertydelete objectName[index]delete property // legal only within a with statement
    Parameters
    objectName
    The name of an object.

    property
    The property to delete.

    index
    An integer representing the array index to delete

    [/code]

    HTH
    Bradley q:)
  • Thanks for your response!

    This is, however, not entirely true... It is true that you can delete properties, but try this:

    [code]
    var obj = new Date(); //Example object...
    obj = null;
    delete obj;
    alert(obj);
    [/code]

    The 'alert' part will infact print "null", instead of "undefined". Since references consume a lot of memory in js, this reference will consume its share until the browser is actually closed. Another good example of this is to go into msdn.microsoft.com/library and see how much memory MSIE consumes as you enter and as you leave - it manages to release about 10% of its consumed memory. You might think MS could manage memory consumtion, but as it is only possible to delete properties and not object, you can only release a part of the consumed memory.

    My problem is that I need to create and delete (large) objects constantly, and since I can't entirely release the memory, the consumed memory will increase as the application is active. So, is there ANY way to overcome this problem? The delete keyword alone constitutes, as mentioned, about 10% of the memory management, so I need something to complete it. Any suggestion?

    Nille
  • : Thanks for your response!
    :
    : This is, however, not entirely true... It is true that you can delete properties, but try this:
    :
    : [code]
    : var obj = new Date(); //Example object...
    : obj = null;
    : delete obj;
    : alert(obj);
    : [/code]
    :
    : The 'alert' part will infact print "null", instead of "undefined". Since references consume a lot of memory in js, this reference will consume its share until the browser is actually closed. Another good example of this is to go into msdn.microsoft.com/library and see how much memory MSIE consumes as you enter and as you leave - it manages to release about 10% of its consumed memory. You might think MS could manage memory consumtion, but as it is only possible to delete properties and not object, you can only release a part of the consumed memory.
    :
    : My problem is that I need to create and delete (large) objects constantly, and since I can't entirely release the memory, the consumed memory will increase as the application is active. So, is there ANY way to overcome this problem? The delete keyword alone constitutes, as mentioned, about 10% of the memory management, so I need something to complete it. Any suggestion?
    :
    : Nille
    :

    Hmmm, interesting that Microsoft doesn't handle the memory consumption that well. I've never used objects as large as what you're talking about so unfortunately I can't help any further!

    Good luck!
    Bradley q:)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories