Python memory

Ok first of all I'd like you guys to know this is like my first thread ever so go easy on me if I'm not doing something right :P

Right then , so I've been programming in python for some time now and I love pretty much everything about this language , but there has always been one thing that was bothering me since day one , and that's the way python manages memory

The main problem here is that literally every single one of my bigger apps (ones written with wxPython GUI for instance) have memory issues (memory leaks?).

So take my last program for instance, it's supposed to capture screen-shots and let you decide what you want to do with the captured bitmap (send it to clipboard, send it to other program or simply save it), and the memory buildup for this program is HUGE

It almost seems like memory of every bitmap I capture never gets released, and just keeps adding up.

I have NO clue how deal with this, I tried searching for topics on this matter but found nothing useful and all the tutorials I read mention nothing about how python manages memory

Since deleting objects doesn't seem to do much, my question is what does :| ?

Isn't there a C++'s free() equivalent in python, or something along those lines ?

I'm really clueless about this matter so I would really appreciate it if some one could just point me in the right direction :\

There is no memory leak in python. Python uses a generational garbage collector which deletes objects when there is no reference left to these objects. You can have look at the gc module which gives you a few functions to interact with the garbage collector, but normally you don't have to.

Of course, it's the programmer's responsibility to ensure that there is no reference to the object. If a living object A has a member B which is a dictionary which contains a value D one of which member is your bitmap object, then the bitmap will not be freed ! The role of the garbage collector is to solve cyclic references.

Every python object stores an integer which is a count of the existing references to the object. An object with a positive refcount will not be freed by the garbage collector. All the objects you can access from your program have a positive refcount (so that you will never see an object with a refcount of 0). However, there is a method sys.getrefcount() which can help you detect hidden references to your object.

I've heard of a special case of 'memory leak' in python: when you load an extension module by importing a shared library, as far as I know, there is no way to 'unload' the library.

There is no memory leak in python. Python uses a generational garbage collector which deletes objects when there is no reference left to these objects. You can have look at the gc module which gives you a few functions to interact with the garbage collector, but normally you don't have to.

Of course, it's the programmer's responsibility to ensure that there is no reference to the object. If a living object A has a member B which is a dictionary which contains a value D one of which member is your bitmap object, then the bitmap will not be freed ! The role of the garbage collector is to solve cyclic references.

Every python object stores an integer which is a count of the existing references to the object. An object with a positive refcount will not be freed by the garbage collector. All the objects you can access from your program have a positive refcount (so that you will never see an object with a refcount of 0). However, there is a method sys.getrefcount() which can help you detect hidden references to your object.

I've heard of a special case of 'memory leak' in python: when you load an extension module by importing a shared library, as far as I know, there is no way to 'unload' the library.

Thank you, I think this pretty much covers everything I needed to know : )

Hi. so this is actually a continuation from another question of mine[Here](https://www.daniweb.com/programming/software-development/threads/506795/dynamically-add-values-into-datagridview-cell-from-listbox-vb2010) but i was advised to start a new thread as the original question …

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...