Python – Working around memory leaks

You can use something like this to help track down memory leaks >>> from collections import defaultdict >>> from gc import get_objects >>> before = defaultdict(int) >>> after = defaultdict(int) >>> for i in get_objects(): … before[type(i)] += 1 … now suppose the tests leaks some memory >>> leaked_things = [[x] for x in range(10)] … Read more

How can I create a reference cycle using dispatchQueues?

You say: From what I understand the setup here is: self —> queue self <— block The queue is merely a shell/wrapper for the block. Which is why even if I nil the queue, the block will continue its execution. They’re independent. The fact that self happens to have a strong reference to the queue … Read more

php/symfony/doctrine memory leak?

Tried doing $cupo->save(); $cupo->free(); $cupo = null; (But substituting my code) And I’m still getting memory overflows. Any other ideas, SO? Update: I created a new environment in my databases.yml, that looks like: all: doctrine: class: sfDoctrineDatabase param: dsn: ‘mysql:host=localhost;dbname=…….’ username: ….. password: ….. profiler: false The profiler: false entry disables doctrine’s query logging, that … Read more

What do I need to do before deleting elements in a vector of pointers to dynamically allocated objects?

Yes Vectors are implemented using template memory allocators that take care of the memory management for you, so they are somewhat special. But as a general rule of thumb, you don’t have to call delete on variables that aren’t declared with the new keyword because of the difference between stack and heap allocation. If stuff … Read more

valgrind memory leak errors when using pthread_create

A thread’s resources are not immediately released at termination, unless the thread was created with the detach state attribute set to PTHREAD_CREATE_DETACHED, or if pthread_detach is called for its pthread_t. An undetached thread will remain terminated state until its identifier is passed to pthread_join or pthread_detach. To sum it up, you have three options: create … Read more

In Linux, how to tell how much memory processes are using?

Getting right memory usage is trickier than one may think. The best way I could find is: echo 0 $(awk ‘/TYPE/ {print “+”, $2}’ /proc/`pidof PROCESS`/smaps) | bc Where “PROCESS” is the name of the process you want to inspect and “TYPE” is one of: Rss: resident memory usage, all memory the process uses, including … Read more