Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few leaks found #1

Open
kgn opened this issue Jun 2, 2011 · 6 comments
Open

A few leaks found #1

kgn opened this issue Jun 2, 2011 · 6 comments

Comments

@kgn
Copy link
Owner

kgn commented Jun 2, 2011

First, a big thanks for this code!!
After running my app through Instruments, I found a few leaks. Below is the info I extracted from Instruments. Let me know if you need anything else.
LEAKED OBJECT: Malloc 16 bytes EVENT TYPE: Malloc RESPONSIBLE CALLER: [InAppSettingsReaderRegisterDefaults loadFile]

  • (void)loadFile:(NSString *)file{ if the file is not in the files list we havn't read it yet NSInteger fileIndex = [self.files indexOfObject:file]; if(fileIndex == NSNotFound){ [self.files addObject:file];
    load plist NSDictionary *settingsDictionary = [[NSDictionary alloc] initWithContentsOfFile:InAppSettingsFullPlistPath(file)]; NSArray *preferenceSpecifiers = [settingsDictionary objectForKey:InAppSettingsPreferenceSpecifiers]; NSString *stringsTable = [settingsDictionary objectForKey:InAppSettingsStringsTable];
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; for(NSDictionary *eachSetting in preferenceSpecifiers){ InAppSettingsSpecifier *setting = [[InAppSettingsSpecifier alloc] initWithDictionary:eachSetting andStringsTable:stringsTable]; if([setting isValid]){ if([setting isType:InAppSettingsPSChildPaneSpecifier]){ [self loadFile:[setting valueForKey:InAppSettingsSpecifierFile]]; }else if([setting hasKey]){ if([setting valueForKey:InAppSettingsSpecifierDefaultValue]){ [self.values setObject:[setting valueForKey:InAppSettingsSpecifierDefaultValue] forKey:[setting getKey]]; } } } [setting release]; } [pool drain]; [settingsDictionary release]; } }
    LEAKED OBJECT: NSCFDictionary EVENT TYPE: Malloc RESPONSIBLE CALLER: [InAppSettingsReaderRegisterDefaults init]
  • (id)init{ self = [super init]; if (self != nil) { self.files = [[NSMutableArray alloc] init]; self.values = [[NSMutableDictionary alloc] init]; [self loadFile:InAppSettingsRootFile]; [[NSUserDefaults standardUserDefaults] registerDefaults:self.values]; } return self; }
    LEAKED OBJECT: NSCFDictionary EVENT TYPE: CFRetain RESPONSIBLE CALLER: [InAppSettingsReaderRegisterDefaults setValues]
    NO CODE HIGHLIGHTED FOR THIS ONE AND I DIDN'T EVEN SEE THIS METHOD **
    LEAKED OBJECT: NSCFDictionary EVENT TYPE: CFRelease RESPONSIBLE CALLER: [InAppSettingsReaderRegisterDefaults dealloc]
    NO CODE HIGHLIGHTED FOR THIS ONE **
    LEAKED OBJECT: NSArrayM EVENT TYPE: Malloc RESPONSIBLE CALLER: [InAppSettingsReaderRegisterDefaults init]
  • (id)init{ self = [super init]; if (self != nil) { self.files = [[NSMutableArray alloc] init]; self.values = [[NSMutableDictionary alloc] init]; [self loadFile:InAppSettingsRootFile]; [[NSUserDefaults standardUserDefaults] registerDefaults:self.values]; } return self; }
    LEAKED OBJECT: NSArrayM EVENT TYPE: Retain RESPONSIBLE CALLER: [InAppSettingsReaderRegisterDefaults setValues]
    NO CODE HIGHLIGHTED FOR THIS ONE AND I DIDN'T EVEN SEE THIS METHOD **
    LEAKED OBJECT: NSArrayM EVENT TYPE: Release RESPONSIBLE CALLER: [InAppSettingsReaderRegisterDefaults dealloc]
    NO CODE HIGHLIGHTED FOR THIS ONE **
@kgn
Copy link
Owner Author

kgn commented Jun 2, 2011

Glad I read this issue before adding this to my project.
Personally I would prefer just to remove the "self." and do a direct assignment because all of these seem to be in the init functions anyway (pointers should be nil at this point). When using "self." the setter is used, which retains the object, and you're passing an autoreleased object. If you assign it directly you avoid using an autorelease and the retainCount is balanced in the dealloc regardless of whether the property is "retain" or "assign". If for some reason later the property was changed to "assign" you won't loose the object by doing a direct assignment (because object ins alloc'ed in init, and released in dealloc).

@kgn
Copy link
Owner Author

kgn commented Jun 2, 2011

I found some leaks and fixed them. I attached the patch.

patch: https://bitbucket-assetroot.s3.amazonaws.com/keegan3d/inappsettings/20101015/27/InAppSettings.20101014.diff

@kgn
Copy link
Owner Author

kgn commented Jun 2, 2011

From and email:
I’ve found that Instruments/leak detection is finding a number of leaks, even when using sample app. I’m hoping it is something I am doing incorrectly here.
For example, when I init default values from my app delegate, leaks are reported in the in the InAppSetttingsRegisterDefaults loadFile function. There are 12 leaks reported. It appears that the retain count of ‘setting’ is 2 immediately before its release.
I’d appreciate any suggestions you may have.

@tblack2200
Copy link

I had posted this original message back on June 2 and was wondering if you would have an updated version of the code soon with the memory leaks fixed?

Thanks

@kgn
Copy link
Owner Author

kgn commented Jul 26, 2011

I haven't been writing iOS apps recently so I haven't looked into this issue.

@kgn
Copy link
Owner Author

kgn commented Jan 24, 2013

I'll need to look into this, hopefully it's fixed with ARC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants