Re: memory leak problem with arrays
- From: "Carl Banks" <invalidemail@xxxxxxxxxxxxxx>
- Date: 15 Jun 2006 05:32:07 -0700
sonjaa wrote:
I've created a cellular automata program in python with the numpy array
extensions. After each cycle/iteration the memory used to examine and
change the array as determined by the transition rules is never freed.
Are you aware that slicing shares memory? For example, say you defined
a grid to do the automata calculations on, like this:
grid = numpy.zeros([1000,1000])
And then, after running it, you took a tiny slice as a region of
interest, for example:
roi = grid[10:20,10:20]
Then deleted grid:
del grid
Then stored roi somewhere, for example:
run_results.append(roi)
If you do this, the memory for the original grid won't get freed.
Although grid was deleted, roi still contains a reference to the whole
1000x1000 array, even though it's only a tiny slice of it. Your poorly
worded description--no offense--of what you did suggests that this is a
possibility in your case. I recommend you try to create a new array
out of any slices you make, like this (but ONLY if the slice doesn't
depend on the memory being shared):
roi = numpy.array(grid[10:20,10:20])
This time, when you del grid, there is no object left referencing the
array data, so it'll be freed.
This might not be your problem. Details are important when asking
questions, and so far you've only given us enough to speculate with.
Carl Banks
.
- Follow-Ups:
- Re: memory leak problem with arrays
- From: sonjaa
- Re: memory leak problem with arrays
- References:
- memory leak problem with arrays
- From: sonjaa
- memory leak problem with arrays
- Prev by Date: interactive programme, using pyTTS
- Next by Date: Re: nested functions
- Previous by thread: Re: memory leak problem with arrays
- Next by thread: Re: memory leak problem with arrays
- Index(es):
Relevant Pages
|