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

UIPasteboard leak in OpenUDID.m #4

Closed
tonyarnold opened this issue Oct 30, 2011 · 5 comments
Closed

UIPasteboard leak in OpenUDID.m #4

tonyarnold opened this issue Oct 30, 2011 · 5 comments

Comments

@tonyarnold
Copy link

Instruments is reporting a leak when running my application that is originating in OpenUDID.m around line 192:

UIPasteboard* slotPB = [UIPasteboard pasteboardWithName:slotPBid create:NO];

It's not a huge leak, but it would be nice to have it sorted. I haven't been able to track down why this is happening, otherwise I'd submit a pull request — do you have any idea why it's happening?

@ylechelle
Copy link
Owner

Hi Tony, good call!.

Unfortunately, I don't know why this constructor call is leaking and not the same one with create:YES
Others, any idea?

Yann

@uvalh
Copy link

uvalh commented Feb 21, 2012

Hi,
don't know if it is still actual but i also got the leaks Tony mention, they appear after re-allocating a class that uses openUDID.

My conclusion is that sending slotPBid for pasteboardWithName
as a dynamic NSString it will increase the retainCount and can cause a problem when the pool try to release the object, if i send a static NSString* const for pasteboardWithName the leaks are gone.
Also i didn't find any docs regarding pasteboardName for sending dynamic NSString it may not work well with dynamic objects.

The problem with openUDID algorithm is that it has to create a dynamic NSString for searching the slots.

What i did to stop the leaks is to call only once [OpenUDID value] and store the udid in the NSUserDefaults.

NSUserDefaults *user_defaults = [NSUserDefaults standardUserDefaults];      
NSString *udid = [user_defaults objectForKey:@"openUDID_udid"];
if(!udid){
    udid = [OpenUDID value];
    [user_defaults setObject:udid forKey:@"openUDID_udid"];
    [user_defaults synchronize];
}

Hope it is helpful.

@ylechelle
Copy link
Owner

Hi,

Thanks for this.
I'll look at the leak and see how else I can fix it.

Using the NSUserDefaults to create yet another copy is perhaps redundant.
Check OpenUDID.m:174 (or about)

    // Do we have a local copy of the OpenUDID dictionary?
    // This local copy contains a copy of the openUDID, myRedundancySlotPBid (and unused in this block, the local bundleid, and the timestamp)
    //
    id localDict = [defaults objectForKey:kOpenUDIDKey];
    if ([localDict isKindOfClass:[NSDictionary class]]) {
        localDict = [NSMutableDictionary dictionaryWithDictionary:localDict]; // we might need to set/overwrite the redundancy slot
        openUDID = [localDict objectForKey:kOpenUDIDKey];
        myRedundancySlotPBid = [localDict objectForKey:kOpenUDIDSlotKey];
        OpenUDIDLog(@"localDict = %@",localDict);
    }

Essentially, if you've called [OpenUDID value] once, then you can subsequently pickup that value from [[[NSUserDefaults standardUserDefaults] objectForKey:kOpenUDIDKey] objectForKey:kOpenUDIDKey]

Yann.

@uvalh
Copy link

uvalh commented Feb 22, 2012

That will do the work. thanks.

Update 2:
meanwhile If its OK with you i added to OpenUDID.h file the line:
#define kOpenUDIDKey @"OpenUDID"
and removed the static NSString * const kOpenUDIDKey from the OpenUDID.m file

Update 1:
In the same context if you already save the openUdid in the user defaults why wont you add return with the value ? is it because you need to update the availableSlotPBid value?

  id localDict = [defaults objectForKey:kOpenUDIDKey];
    if ([localDict isKindOfClass:[NSDictionary class]]) {
        localDict = [NSMutableDictionary dictionaryWithDictionary:localDict]; // we might need to set/overwrite the redundancy slot
        openUDID = [localDict objectForKey:kOpenUDIDKey];
        myRedundancySlotPBid = [localDict objectForKey:kOpenUDIDSlotKey];
        OpenUDIDLog(@"localDict = %@",localDict);
        return openUDID;
    }

@ylechelle
Copy link
Owner

closing this because the issue was in fact fixed on September 9 by adding the kOpenUDIDSessionCache static variable.

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

No branches or pull requests

3 participants