where to release a CF object thats retained by a cocoa object
where to release a CF object thats retained by a cocoa object
- Subject: where to release a CF object thats retained by a cocoa object
- From: Navneet Kumar <email@hidden>
- Date: Sun, 27 Sep 2009 22:41:34 +0530
Hi,
From a method in my AppController class I'm calling a function in
another file as follows:
In AppController in init method:-
[self initialDriveList];
In AppController in initialDriveList method:
//some code here
[self volumeList];
// rest of the code here
In AppController in volumeList method:
finalArrayForVolumes = [[NSMutableArray alloc] init];// an ivar in
AppController class
// adding some objects of type NSMutableDictionary to the
finalArrayForVolumes here
FindVolumeNames((CFMutableArrayRef)finalArrayForVolumes);
[finalArrayForVolumes retain];
In another file in FindVolumeNames() function:
void FindVolumeNames(CFMutableArrayRef response)
{
CFIndex count = CFArrayGetCount(response);
int i;
for (i = 0; i < count; i++)
{
CFMutableDictionaryRef data = (CFMutableDictionaryRef)
CFArrayGetValueAtIndex (response, i);
// some code here
CFStringRef outputVolumeName = CFStringCreateWithSubstring
(kCFAllocatorDefault, pathName, rangeResult);// line 176, Call to
function 'CFStringCreateWithSubstring' returns a Core Foundation
object with a +1 retain count (owning reference)
CFDictionaryAddValue(data, CFSTR(kVolumeName), outputVolumeName);
// Shall I do CFRelease(outputVolumeName); here?
//some code here
}//Object allocated on line 176 and stored into 'outputVolumeName' is
no longer referenced after this point and has a retain count of +1
(object leaked)
//some code here
}
The warnings returned by static analyzer in Xcode3.2 are mentioned in
the code above.
Main warning was: Potential leak of an object allocated on line 176
and stored into 'outputVolumeName'
The problem is where to release this outputVolumeName, which is added
to a dictionary which is added to an array allocated in AppController?
And will that lead to removal of this warning?
I gather there is no autorelease in CF.
Wishes,
Nick
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden