Are not used Objects cleaned from memory?

Discussion in 'Ruby' started by Iñaki Baz Castillo, Jul 13, 2008.

  1. Hi, a simple question:
    If I have an Array containing custom complex objects and I use Array.delete=
    or=20
    any other function that deletes a element of the Array, will be the deleted=
    =20
    Object remain in RAM memory? or will it automatically deleted?
    Note that the object also contains complex objects as attributes.

    Thanks.

    =2D-=20
    I=C3=B1aki Baz Castillo
    Iñaki Baz Castillo, Jul 13, 2008
    #1
    1. Advertising

  2. I=C3=B1aki Baz Castillo wrote:
    > If I have an Array containing custom complex objects and I use Array.dele=

    te
    > or any other function that deletes a element of the Array, will be the
    > deleted Object remain in RAM memory? or will it automatically deleted?


    Assuming the object is not referenced in any other way it will be garbage=20
    collected.

    HTH,
    Sebastian
    Sebastian Hungerecker, Jul 13, 2008
    #2
    1. Advertising

  3. Iñaki Baz Castillo

    Dave Bass Guest

    Sebastian Hungerecker wrote:
    > Assuming the object is not referenced in any other way it will be
    > garbage
    > collected.


    Eventually.

    AFAIK there is no way to force the garbage collector to operate; this is
    in common with most other languages that use garbage collection.
    GC.start or GC.enable do not *force* garbage collection to occur.

    But I'm by no means an expert, so someone will probably be along in a
    minute to tell you about a gem that does just that... or it's already in
    v1.9... :)

    Dave


    --
    Posted via http://www.ruby-forum.com/.
    Dave Bass, Jul 14, 2008
    #3
  4. On 14/07/2008, Dave Bass <> wrote:
    > Sebastian Hungerecker wrote:
    > > Assuming the object is not referenced in any other way it will be
    > > garbage
    > > collected.

    >
    >
    > Eventually.
    >
    > AFAIK there is no way to force the garbage collector to operate; this is
    > in common with most other languages that use garbage collection.
    > GC.start or GC.enable do not *force* garbage collection to occur.
    >
    > But I'm by no means an expert, so someone will probably be along in a
    > minute to tell you about a gem that does just that... or it's already in
    > v1.9... :)
    >


    There might be some non-obvious references to objects stored in blocks
    or elsewhere. When you write a piece of code (such as a block) and
    save it somewhere the variables that were visible while writing the
    block have to be kept around.

    Also from what I have heard the GC works by scanning the memory
    (stack, whatever) for things that *look* like object pointers. So if
    you have a number (or substring, or ...) that points to an object when
    interpreted as a pointer that object would not be deleted even though
    it is really not referenced ...

    When I created lots of small strings and stuffed them into numerous
    hashes and arrays the objects did not go away as I would expect. I
    saved a gigabyte or two of ram by using JRuby then - it required about
    half the memory in this case ;-)

    Thanks

    Michal
    Michal Suchanek, Jul 15, 2008
    #4
  5. Iñaki Baz Castillo

    Marc Heiler Guest

    > AFAIK there is no way to force the garbage collector to operate;

    Hmm GC.start ?

    Or maybe wait until you have 8M used, then it should kick in ... :)
    --
    Posted via http://www.ruby-forum.com/.
    Marc Heiler, Jul 16, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Saunders
    Replies:
    2
    Views:
    515
    John Saunders
    Jul 22, 2003
  2. =?Utf-8?B?U3Jpbml2YXM=?=

    When will the Temporary ASP.NET files be cleaned

    =?Utf-8?B?U3Jpbml2YXM=?=, Mar 22, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    370
    Brock Allen
    Mar 22, 2005
  3. InterScan Notification
    Replies:
    0
    Views:
    255
    InterScan Notification
    Sep 2, 2003
  4. blackpawn
    Replies:
    5
    Views:
    266
    Hrvoje Niksic
    Mar 26, 2008
  5. TP
    Replies:
    2
    Views:
    233
    Mensanator
    Mar 26, 2009
Loading...

Share This Page