Re: Mixing Cpp and ObjC - Memory Leak in ARC
Re: Mixing Cpp and ObjC - Memory Leak in ARC
- Subject: Re: Mixing Cpp and ObjC - Memory Leak in ARC
- From: Jean-Daniel <email@hidden>
- Date: Sun, 27 Nov 2016 19:13:10 +0100
> Le 27 nov. 2016 à 19:12, Jean-Daniel <email@hidden> a écrit :
>
> Just a though, but have you tried to enclose your obj-c code into an @autorelease block ?
>
> AFAIK, the BlackMagic SDK don’t create autorelease pool for you.
>
>> Le 27 nov. 2016 à 17:40, Hado Hein Applelists <email@hidden> a écrit :
>>
>>
>> Hoi,
>> I have to use a SDK that is written in cpp.
>>
>> Since I have to include the .hpp header of the SDK I also had to switch my AppDelegate.m to .mm
>> I’m using ARC.
>>
>>
>> Now I have another cpp source file that makes use of this SDK. It defines a cpp class which also works.
>> In some callback of the class I need to call out to my AppDelegate.
>>
>>
>>> HRESULT DeckLinkCaptureDelegate::VideoInputFrameArrived(IDeckLinkVideoInputFrame* videoFrame, IDeckLinkAudioInputPacket* audioFrame)
>>
>>
>> But this eats memory. First I did it in a direct call on my
>>> [iter setAvgColor:[NSColor colorWithRed:r green:g blue:b alpha:1]].
>> This produced a ~1MB per second memory leak.
>>
>> Then I went to:
>>> dispatch_async(dispatch_get_main_queue(), ^{
>>> [iter performSelectorOnMainThread:@selector(setAvgColor:) withObject:[NSColor colorWithRed:r green:g blue:b alpha:1] waitUntilDone:YES];
>>> });
>>
>> Which brought down the leak to <100kB/sec. But it’s still there.
>>
>> Then I tried not to allocate a Foundation Object in the cpp code and tried:
>>
>>> [iter setAvgColorWithR:r G:g B:b];
>> and allocating the NSColor in the source of my iter-objc-class.
>>
>> This didn’t work either.
>>
>>
>>
>>
>> Now I’m wondering what I’m doing wrong.
>>
>> The class cpp does not contain any obj-c code or objects. It just includes the AppDelegate.h for calling out.
>>
>> Unfortunately, when I turn on Malloc Debug Functions in Xcode the thing does not compile anymore. So I’m a bit lost on how to find the exakt position of the leak and on how to implement this correctly. I assume that this might have to do something with using a Foundation constructor In cpp code which doesn’t arc correctly.
>>
>>
>> Thx, Hado
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Xcode-users mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden