Hi,

When I alloc and init a NSString the following way, there is warning that: Potential leak of an object allocated on line 526 and stored in sizeDisp. 1. Method returns an Objective-C object with a +1 retain count (owning reference). 2. Object returned to caller as an owning reference (single retain count transferred to caller). 3. Object allocated on line 526 and stored into 'sizeDisp' is returned from a method whose name ('tableView:objectValueForTableColumn:row:') does not contain 'copy' or otherwise starts with 'new' or 'alloc'. This violates the naming convention rules given in the Memory Management Guide for Cocoa (object leaked).

The code is as follows:

                if ([[tableColumn identifier] isEqual:@"Size"] == YES)
                {
                        NSString *sizeDisp;// line 526
                        NSNumber *size = [data objectForKey:@kDeviceSize];
                        unsigned long long sizeInBytes = [size 
unsignedLongLongValue];
                        if (sizeInBytes < 1000*1000)
                        {
sizeDisp = [[NSString alloc] initWithFormat:@"%.2f KB", ((float) sizeInBytes/1000)];
                        }
                        else if (sizeInBytes < 1000*1000*1000)
                        {
sizeDisp = [[NSString alloc] initWithFormat:@"%.2f MB", ((float) sizeInBytes/(1000*1000))];// warning number 1 (as listed above)
                        }
                        else
                        {
sizeDisp= [[NSString alloc] initWithFormat:@"%.2f GB", ((float) sizeInBytes/(1000*1000*1000))];
                        }
                        return sizeDisp;// warning 2 & 3 (as listed above)
                }

When I do sizeDisp = [NSString stringWithFormat:@"%.2f MB", ((float) sizeInBytes/(1000*1000))];
The warning disappears in the next build and analyze.

Can I hope for a small analysis of the above from anybody?

Thanks,
Nick


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to