Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Memory usage

From: lmecir:mbox:vol:cz at: 19-Oct-2005 10:12

Hi Christophe, ....
>I did also have a lot of trouble with REBOL garbage collecting strategy. >Assuming 'recycle would work like a C deallocation function, I used it a >lot into some of my resources-consuming scripts. But one day I stated >the following: > >>>stats >>> >>> >4183470 > >>>my-string: make string! 10000000 >>> >>> >"" > >>>stats >>> >>> >13186209 ;-> + 10MB > >>>recycle >>>stats >>> >>> >13186065 ;-> Gee! Didn't work at all ??? >
This is a special case not handled by the Garbage Collector as you correctly found out. The GC "thinks", that you are going to need this allocated memory when you allocated it intentionally. Therefore, it will not "shrink" the space.
>After a few try-and-errors, I found that first using a 'make on the word >previously to the call to 'recycle, solves the problem: >
>>>my-string: make none! none >>> >>> >none >
my-string: none or my-string: copy "" or unset 'my-string would suffice.
>>>stats >>> >>> >13186577 ;-> just checking: nothing happened > >>>recycle >>>stats >>> >>> >3185714 ;-> memory obviously freed >
Right. RECYCLE call was not totally necessary, because it would happen automatically sooner or later anyway.
>You do not have to use a 'make none! To achieve this: a call to 'make >string! "" or whatever does the job too. >
>I solve most of my memory problem using this 'free-memory function: > >free-memory: func ['w][set :w make none! none recycle] >
The shortest way may be to just write: unset 'w or w: none or w: copy "" or anything else not reserving too much memory as you wrote above instead of: free-memory w The Garbage Collector is being called regularly anyway. If you call RECYCLE too often, you are unnecessarily slowing down the interpreter.
>You can find an interesting thread about this subject on the French >REBOL forum: >
I tried the URL and I got a C++ related page?
>Now, I do not know if this is the regular use of 'recycle, as meant by >RT. Or if this is a buggy thing... Perhaps have the list's gurus some >thoughts about that? > >Anyway, I hope this will help :-) > >Dchristophe >
Yes, I think that those comments are helpful for somebody trying to figure what is and what isn't collected by the GC. (Maybe we should put it to a REBOL doc somewhere?) -L