[Pyobjc-dev] [ pyobjc-Bugs-1982104 ] Possible memory leak returnig NSData or NSDictionary
Brought to you by:
ronaldoussoren
From: SourceForge.net <no...@so...> - 2008-06-02 13:19:31
|
Bugs item #1982104, was opened at 2008-06-02 06:19 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=114534&aid=1982104&group_id=14534 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Barry Wark (barrywark) Assigned to: Nobody/Anonymous (nobody) Summary: Possible memory leak returnig NSData or NSDictionary Initial Comment: I have an Objective-C application that uses plugins to generate some data. THe app is compiled against the 10.5 SDK and is running on Leopard (with the system python and pyobjc). The data is returned as NSData instances and its parameters as an NSDictionary instance, as defined by the app's plugin formal protocol. Some of our plugins are written in Objective-C and some in Python ("compiled" with py2app). The app is compiled against the 10.5 SDK and is running on Leopard (with the system python and pyobjc). I've noticed that there's a signficant apparent memory leak in the application when using Python-based plugins, but not when using the Objective-C based plugins. Therefore, I've concluded that the issue is with the plugins, not the main application. I've written a small demo app that exhibits the apparent leak behavior. The relevant sections of the Objective-C side are: - (IBAction)getDataFromPython:(id)sender { id<TestProtocol> plugin = [[pluginClass alloc ] init]; NSAssert([plugin conformsToProtocol:@protocol(TestProtocol)], @"Plugin not id<TestProtocol>."); for(NSUInteger i=0; i<self.nReps; i++) { NSData *d = [plugin getNumpyData]; } [plugin release]; } - (IBAction)getDictFromPython:(id)sender { id<TestProtocol> plugin = [[pluginClass alloc ] init]; NSAssert([plugin conformsToProtocol:@protocol(TestProtocol)], @"Plugin not id<TestProtocol>."); for(NSUInteger i=0; i<self.nReps; i++) { NSDictionary *d = [plugin getDictionary]; } [plugin release]; } and the corresponding "getNumpyData" and "getDictFromPython" methods in the plugin are: import numpy as np def getNumpyData(self): return np.zeros(10000) def getDictionary(self): return NSDictionary.dictionaryWithObjectsAndKeys_('abc', 'string', pkl.dumps(np.zeros(1000)), 'pkl_string', None) Investigation with ObjectAlloc in Instruments suggests that the instances of "GeneralBlock" in the first case (getNumpyData) and "GeneralBlock" and CFDictionary in the second (getDictionary) case are created but not released, even after the event loop (and associated NSAutoreleasePool.drain) are completed. This is not the case with an equivalent Objective-C plugin. Is it possible that this is a memory leak caused by improper reference management across the Objective-C/python bridge? I've included a zip file with the Xcode project (app and plugins (python and objective-c). The project folder also contains an Instruments file that will drive and record the behavior I describe above. Thanks! ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=114534&aid=1982104&group_id=14534 |