qt:heap_versus_stack
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
qt:heap_versus_stack [2010/12/08 22:04] – mithat | qt:heap_versus_stack [2010/12/08 22:12] – [Short answer] mithat | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Heap or Stack? ====== | ====== Heap or Stack? ====== | ||
- | Should Qt objects be creates | + | Should Qt objects be created |
+ | ===== Short answer ===== | ||
+ | If the object is going to be part of a tree of Qt objects (as will be the case for most Qt GUI objects), then it should be created on the heap. | ||
+ | |||
+ | If the object is not part of a tree or is the root of a tree, then it can be created either on the heap or the stack. It seems to be a tradition (or maybe there' | ||
+ | |||
+ | ===== Long answer ===== | ||
In contrast to many modern programming languages, C++ has no automatic memory management. The traditional approach to managing dynamically allocated storage in C++ is to explicitly delete allocated memory that you no longer require. When you are dealing with large trees of objects, this can become quite tedious and the source of errors (especially memory leaks). | In contrast to many modern programming languages, C++ has no automatic memory management. The traditional approach to managing dynamically allocated storage in C++ is to explicitly delete allocated memory that you no longer require. When you are dealing with large trees of objects, this can become quite tedious and the source of errors (especially memory leaks). | ||
qt/heap_versus_stack.txt · Last modified: 2010/12/08 22:59 by mithat