Anything involving names in locales needs explicit GC. So, for example:
thingy=: i.1e6 That name - thingy - will persist until you explicitly release it. Locales actually make this a bit easier (since you can erase the entire locale rather than having to erase all the names in it). The problem comes when you have been trained to use millions of tiny objects. That's a bad habit not just because of "GC", but because it's a poor use of space and time, in J. Generally speaking, in J you want to arrange things so the low level structures are regular and the complexity bubbles up to the top levels. This tends to be great for comprehension, but painful or worse when you are not supposed to be able to understand what you are working on. Thanks, -- Raul On Thu, Oct 12, 2017 at 5:50 AM, 'Jon Hough' via Programming <[email protected]> wrote: > Is there a reason J doesn't perform GC on objects? I was unaware we had to > destroy our own objects > (In retrospect, I guess the existence of codestroy was a hint ). > > Example: > > oclass 'B' > > create=: 3 : 0 > > Mat=: ? (y,y) $ 0 > ) > > destroy=: codestroy > > > > > coclass 'A' > > > create=: 3 : 0 > iterations=: y > myB=: '' > ) > > > runLoop=: 3 : 0 > ctr=: 0 > while. ctr < iterations do. > myB=: 400 conew 'B' > ctr=:>:ctr > end. > 'finished' > ) > > > destroy=: codestroy > > > myA=: 1000 conew 'A' > runLoop__myA 0 > NB. Let myB reference an int now. It might be expected that the > NB. 400x400 matrix's memory allocation was freed, but it > NB. is still there. > myB__myA=: 1 > > Viewing memory usage in htop or Activity Monitor, this program goes into the > Gigabytes quickly and as far as I can see the > memory is never reclaimed. > I am not complaining, I am just wondering, why unreferenced objects are not > GCed, > and also recommend that OOP explanations in the Wiki, JforC (assuming a new > edition) be a little more explicit > in the necessity of codestroy. > > This is A's runLoop that destroy unreferenced objects > runLoop=: 3 : 0 > ctr=: 0 > while. ctr < iterations do. > if.-. myB -: '' do. > destroy__myB '' > end. > myB=: 400 conew 'B' > ctr=:>:ctr > end. > 'finished' > ) > > > Using this, memory allocation does not increase. I'm sure this is probably > obvious to J experts, but as far as I can see, doing there is > no explicit explanaiton of this anywhere. > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
