Please help me with this memory leak. In the leaks tool it shows a leak: NSCFString (32 bytes) in the library Foundation
Responsible Frame: NSPropertyListSerialization
. I am releasing the error but still a leak. What am I missing? Many thanks!
NSPropertyListFormat format;
NSString *anError = nil;
id plist;
plist = [NSPropertyListSerialization propertyListFromData:rawCourseArray mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&anError];
if (!plist){
[anError release];
}
NSArray *entries = (NSArray *)plist;
for (NSDictionary *entry in entries)
{
// DO SOMETHING
}
To find a memory leak, look at how much RAM the system is using. The Resource Monitor in Windows can be used to accomplish this. In Windows 8.1 and Windows 10: To open the Run dialogue, press Windows+R, then type "resmon" and click OK.
Stack memory leaks occur when a method keeps getting called but never exits. This can happen if there is an infinite loop or if the method is being called with different data each time but the data is never used. Eventually, the stack will fill up and the program will run out of memory.
Memory leak occurs when programmers create a memory in heap and forget to delete it. The consequences of memory leak is that it reduces the performance of the computer by reducing the amount of available memory.
The memory leak would occur if the floor number requested is the same floor that the elevator is on; the condition for releasing the memory would be skipped. Each time this case occurs, more memory is leaked. Cases like this would not usually have any immediate effects.
First, make sure that you are not using deprecated or obsolete method calls. Depending on your app configuration (this is for you to decide) you may be using obsolete method calls; from Apple docs:
propertyListFromData:mutabilityOption:format:errorDescription:
This method is obsolete and will be deprecated soon. (Deprecated. Use
propertyListWithData:options:format:error:
instead.)
I did not detect a memory leak after using the recommended api call... Test Code:
NSArray *somearray = @[@"One",@"Two",@"Three"];
NSData *rawCourseArray = [NSKeyedArchiver archivedDataWithRootObject:somearray];
NSPropertyListFormat format;
NSError *anError = nil;
id plist;
plist = [NSPropertyListSerialization propertyListWithData:rawCourseArray options:NSPropertyListImmutable format:&format error:&anError];
if (!plist){
[anError release];
}
NSArray *entries = (NSArray *)plist;
for (NSDictionary *entry in entries)
{
// DO SOMETHING
NSLog(@"%@",entry);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With