memory management with lists
Eric DeWitt <[email protected]>
| Newsgroups | gmane.comp.breve |
|---|---|
| Message-ID | <[email protected]> |
I have written a genetic engine that uses lists internally for data
structures. Unfortunately, I create a lot of lists on the fly while
updating the genome by using "myVar = { ... }" constructs. When I
observe the top level lists (those that contain the lists which are
used as data structures) in the Selection Inspector, I can see that the
top level list is getting replaced (as expected) as I create new lists
containing the same items as the original list (not using a copy, just
pushing the sub-lists onto a local method variable and returning the
new list). Occasionally new sub-lists (the data structure lists) could
be created or removed, but the test I have been running doesn't even do
that. The iteration code (vastly simplified) looks something like
this. Important to note that the only place that I think I am creating
a new list is in the pushing existing data structure lists onto the
local variable.
+ to iterate:
objectNewList = (self update-genome with objectOrginalList).
+ update-genome with objectList (list):
myNewList (list).
placeHolder (list).
foreach placeHolder in objectList:{
do stuff with placeHolder{0}.
do stuff with placeHolder{1}.
...
push placeHolder onto myNewList.
}
return myNewList.
+ to post-iterate:
objectOrginalList = objectNewList.
However, the memory consumption is astronomical! I can chew threw a
gig in a little less 60s (wall clock). I cannot quite see how this is
possible if I am only creating (and abandoning) the few pointers used
in the outer lists--but I don't see any other explanation (there is not
a single 'new' in the code). I have tried 'free'ing lists where ever
possible, but often this has led to unexpected crashes (with either bad
memory access protection faults or malloc double free on the same
address errors). Has anyone else tried to do anything like this? Do
lists of lists in local variables get freed when the variables are
reset for the next iteration? I am trying to eliminate the use of
temporary lists where possible, but it makes some algorithms difficult
to implement. Given that we have no garbage collection, what do people
recommend for managing references to lists and freeing them. (I am a
bit out of practice with this kind of memory management, being too long
in the OO and GC worlds...)
Thanks for any thoughts.
-eric
_______________________________________________
breve mailing list
[email protected]
http://www.spiderland.org/mailman/listinfo/breve