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

Reply via email to