memory-management

How do i use subprocesses to force python to release memory?

How do i use subprocesses to force python to release memory? Question: I was reading up on Python Memory Management and would like to reduce the memory footprint of my application. It was suggested that subprocesses would go a long way in mitigating the problem; but i’m having trouble conceptualizing what needs to be done. …

Total answers: 2

What is the recommended way of allocating memory for a typed memory view?

What is the recommended way of allocating memory for a typed memory view? Question: The Cython documentation on typed memory views list three ways of assigning to a typed memory view: from a raw C pointer, from a np.ndarray and from a cython.view.array. Assume that I don’t have data passed in to my cython function …

Total answers: 2

out of memory issue in installing packages on Ubuntu server

out of memory issue in installing packages on Ubuntu server Question: I am using a Ubuntu cloud server with limited 512MB RAM and 20 GB HDD. Its 450MB+ RAM is already used by processes. I need to install a new package called lxml which gets complied using Cpython while installation and its a very heavy …

Total answers: 1

Create a figure that is reference counted

Create a figure that is reference counted Question: It seems that the standard way of creating a figure in matplotlib doesn’t behave as I’d expect in python: by default calling fig = matplotlib.figure() in a loop will hold on to all the figures created, and eventually run out of memory. There are quite a few …

Total answers: 3

Releasing memory in Python

Releasing memory in Python Question: I have a few related questions regarding memory usage in the following example. If I run in the interpreter, foo = [‘bar’ for _ in xrange(10000000)] the real memory used on my machine goes up to 80.9mb. I then, del foo real memory goes down, but only to 30.4mb. The …

Total answers: 4

Python multiprocessing memory usage

Python multiprocessing memory usage Question: I have writen a program that can be summarized as follows: def loadHugeData(): #load it return data def processHugeData(data, res_queue): for item in data: #process it res_queue.put(result) res_queue.put("END") def writeOutput(outFile, res_queue): with open(outFile, ‘w’) as f res=res_queue.get() while res!=’END’: f.write(res) res=res_queue.get() res_queue = multiprocessing.Queue() if __name__ == ‘__main__’: data=loadHugeData() p …

Total answers: 2

Does Python have a stack/heap and how is memory managed?

Does Python have a stack/heap and how is memory managed? Question: How are variables and memory managed in Python? Does it have a stack and a heap and what algorithm is used to manage memory? Given this knowledge are there any recommendations on memory management for large number/data crunching? Asked By: Matt Alcock || Source …

Total answers: 2

Memory use during recursion in Python

Memory use during recursion in Python Question: I’ve implemented a recursive function which takes as parameter a numpy array. Here the simplified version: def rec(arr): rec(arr[indices]) In every recursive call I use a part of the array indexed by some indices. My question is about the memory load: how does python handle this? Does it …

Total answers: 1

Python "range" resource consumption

Python "range" resource consumption Question: I wrote the following script Basically, I’m just learning Python for Machine Learning and wanted to check how really computationally intensive tasks would perform. I observe that for 10**8 iterations, Python takes up a lot of RAM (around 3.8 GB) and also a lot of CPU time (just froze my …

Total answers: 5