It depends on what is meant by "garbage collection". There is definitely no memory compaction, moving stuff around so that free blocks are collected together into one contiguous block. Memory compaction does not make sense in modern virtual memory systems.
As far as memory management is concerned: a. When J needs memory, it gets it from malloc(); when it knows that memory is not longer used, it frees it using free(). (For efficiency there is a separate mechanism for blocks of size 1024 bytes or smaller, but the main point remains valid.) b. Everything is an array. Arrays are reference counted. When the reference count goes to 0, the array is freed. c. The reference count can go to 0 in various ways, with some ways more obvious than others. x=: i.1e7 4!:55 <'x' In the erase, the interpreter knows that the instance of i.1e7 will never be referenced by the user again, so it frees that memory. Likewise, x=: i.1e6 x=: 7 The instance of i.1e6 will never be referenced again, so would be freed by the interpreter. foo=: 3 : 0 t=. i. y $ t ) foo 2e6 2000000 When foo exits, J knows that whatever is in t at that time will never be referenced again, so frees that space. d. You can discover what happens to a large extent through use of the 7!:0 foreign (space currently in use): 7!:0 '' 1151296 foo 2e6 2000000 7!:0 '' 1151296 foo 1e7 10000000 7!:0 '' 1151296 x=: i.2e6 7!:0 '' 9539904 4!:55 <'x' 1 7!:0 '' 1151296 ----- Original Message ----- From: Tracy Harms <[EMAIL PROTECTED]> Date: Saturday, March 3, 2007 11:05 am Subject: [Jgeneral] garbage (and the collection thereof) > It is my understanding that there is no automatic > garbage collection in J. Is this assertion correct? > > I ask because it came to mind as I read "Good Ideas, > Through the Looking Glass" by Niklaus Wirth. In it he > writes of functional programming languages that 'a > garbage collector is the necessary ingredient. An > implementation without automatic garbage collection is > unthinkable.' > > Notice that said article was published Jan. 2006! > (IEEE Computer) > > http://www.cs.inf.ethz.ch/~wirth/Articles/GoodIdeas_origFig.pdf > > -- > Perhaps the most important habit in the > development of good style in a language > [is] the habit of critical reading. > Kenneth E. Iverson ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
