Issue #199 closed

Pyobjc objects stays in memory after del

mostafa
created an issue

Hello, I am using pyobjc to access a library running on MAC OS SIERRA 10.12.2 In python I create an object let say belongs to pyobjc. I call many functions or methodes belong to this object, but memmry increase 1 MB/min I started debugging, I just do:

import myobj# check top command memory has 41 mb of python usage
del myobj #memory still the same in top command

seems that del cannot clean or unimport pyobjc objects.

any work arround how to do this? Thank you in advance.

Comments (5)

  1. Ronald Oussoren repo owner
    • edited description

    Could you please provide an actual example of this?

    Do you do this in a GUI program with an event loop or are you calling lots of methods in a script that doesn't use a Cocoa event loop? If its the latter you might run into Cocoa's autorelease pool (a memory management feature for Objective-C).

  2. mostafa reporter

    Hello Dear Ronald. example : I run top command to see python process how much memory is consuming, i kill all python processes.

    then I run this script:

    import weakref import objc, time from Foundation import NSAutoreleasePool from pypbjc_custom_class import Device

    class MyClass(Device): def init(self): """ Designated initializer for MyClass """

        self.pool = NSAutoreleasePool.alloc().init()
        self = objc.super(MyClass, self).init()
        if self is None: 
            return None
    
        self.devices=Device.allDevices()
        return self
    
    def __del__(self):
        print "......................................................"
        # self.pool.release()
    

    myInstance = MyClass.alloc().init() print len(myInstance.devices) myInstance.dealloc()

    del myInstance

    here python memory stays full, and more memory what python took at beginning. means myInstance increased the memory of python process, but when dealloc or del the memorry

    doesnot decrese to python supposed consumed memory.

    if I run the script in a thread with 100 loops, the memory increase every minute 1 M

    I could see that dealloc not free the memory.

    but if you find my example not understoodable, please just tell me how can free memory after using a pyobjc class instance, when importing or when subclassing it.

    please send me an example.

    time.sleep(20)

  3. mostafa reporter

    Hello Dear Ronald. example : I run top command to see python process how much memory is consuming, i kill all python processes.

    then I run this script:

    import weakref import objc, time from Foundation import NSAutoreleasePool from pypbjc_custom_class import Device

    class MyClass(Device): def init(self): """ Designated initializer for MyClass """

        self.pool = NSAutoreleasePool.alloc().init()
        self = objc.super(MyClass, self).init()
        if self is None:
            return None
    
        self.devices=Device.allDevices()
        return self
    
    def __del__(self):
        print "......................................................"
        # self.pool.release()
    

    myInstance = MyClass.alloc().init() print len(myInstance.devices) myInstance.dealloc()

    del myInstance

    here python memory stays full, and more memory what python took at

    beginning. means myInstance increased the memory of python process, but when dealloc or del the memorry

    doesnot decrese to python supposed consumed memory.

    if I run the script in a thread with 100 loops, the memory increase every

    minute 1 M

    I could see that dealloc not free the memory.

    but if you find my example not understoodable, please just tell me how can

    free memory after using a pyobjc class instance, when importing or when subclassing it.

    please send me an example.

    time.sleep(20)

  4. Ronald Oussoren repo owner

    Please try to format your message properly, it is very hard to read the code this way.

    Please add a complete script that I can use to reproduce the problem, without such a script it is close to impossible to determine what's going on.

  5. Log in to comment