Archive | memory leak RSS feed for this section

Memory management in C++ Part 2

29 Jun

While part 1 focussed on avoiding memory leaks, this post will look at memory strategies which optimize speed. While in many cases a normal allocation/reallocation/deallocation scheme works well, there are several instances where this can slow down software considerably. In these cases one of the following strategies can help to improve the performance of your application.

Continue reading

Memory management in C++ Part 1

23 Jan

While scripting and other high level languages often have one way to manage memory, working with a lower level language gives you the ability to choose how to manage each allocated piece of memory. This can be both a blessing and a curse, as one way is not always the best solution for each case, so choosing the best strategy can become hard. This article tries to give an overview of several techniques.

Continue reading

Fixing and avoiding memory leaks in Python

12 Apr

Reference counting

Python uses reference counting for its memory management. This means that it keeps count of how many references your script still has to an object, and when that count becomes zero, the object is deleted.

a = "text"
b = a
a = None
b = None

The string object containing “text” is deleted after the last reference, in this case b, is set to None (or any other value).

The problem of circular references

A problem arises when one object holds a reference to another which has a reference back to the first, either directly or in a chain. This is not so hypothetical, as it often happens in hierarchical or cyclic graph structures. In the following tree structure for example, parent nodes hold references to child nodes, while the child nodes hold references to their parent. Continue reading