Re: [Pyobjc-dev] Possible memory leak passing Cocoa NSData or NSDictionary instances from python pl
Brought to you by:
ronaldoussoren
|
From: Barry W. <bar...@gm...> - 2008-06-02 02:43:15
|
The equivalent Objective-C methods look like:
- (NSData*)getNumpyData {
return [NSMutableData dataWithLength:10000*sizeof(float)];
}
- (NSDictionary*)getDictionary {
char str[10000];
str[10000-1]=0;
return [NSDictionary dictionaryWithObjectsAndKeys:@"abc",
@"string",
[NSMutableString stringWithCString:str
encoding:NSUnicodeStringEncoding],
@"pkl_string",
nil];
}
I didn't include the Objective-C version in the zip file/project since
calling these methods does NOT produce an increase in memory usage
following the end of the event loop (or any non-deallocated objects in
instruments). In the case of getDictionary, I've tried to replicate an
approximate equivalent string to the pickle.dumps call in the python
protocol.
As you can see, I'm relying on the bridging of buffer
protocol-implementing objects such as numpy's ndarray <-> NSData in
the pyobjc bridge.
Barry
On Sun, Jun 1, 2008 at 7:17 PM, s s <li...@in...> wrote:
>
> On Jun 1, 2008, at 9:57 PM, Barry Wark wrote:
>>
>> 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)
>
> What do the Obj-C test versions of these two same methods look like?
>
> S
>
>
>
|