Getting memory leak in instruments when i m trying to test app. In app when i test youtube video in UIWebView it shows malloc Memory Leak in libsystem_c.dylib responsible framse showing is strdup.
-(void)LaunchVideo:(id)sender
{
self.videoURL = #"http://www.youtube.com/embed/0Xa4bHcJu8";
//VideoViewController *videoViewController = [[[VideoViewController alloc] initWithNibName:nil bundle:nil] retain];
VideoViewController *videoViewController = [[VideoViewController alloc] init];
videoViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
videoViewController.videoURL = self.videoURL;
[self presentModalViewController:videoViewController animated:YES];
[videoViewController release];
}
EDIT:
Below is the stack trace:
0 libsystem_c.dylib malloc
1 libsystem_c.dylib strdup
2 libnotify.dylib token_table_add
3 libnotify.dylib notify_register_check
4 AVFoundation -[AVPlayer(AVPlayerMultitaskSupport) _iapdExtendedModeIsActive]
6 AVFoundation -[AVQueuePlayer init]
7 MediaPlayer -[MPQueuePlayer init]
23 MediaPlayer -[UIMoviePlayerController setAutoRotationMask:]
24 QuickTime Plugin 0x89473ce
27 QuickTime Plugin 0x894f3bc
28 libdispatch.dylib _dispatch_call_block_and_release
29 libdispatch.dylib _dispatch_main_queue_callback_4CF$VARIANT$mp
30 CoreFoundation __CFRunLoopRun
32 CoreFoundation CFRunLoopRunInMode
33 GraphicsServices GSEventRunModal
34 UIKit UIApplicationMain
Anyone can tell why the leak is and what is the cause.
Thanks.
Tried googling for similar problems? I just did, and I found this:
iOS libsystem_c.dylib strdup memory leak NSZombie not working
To summarise, it may be a leak in a library you're not responsible for. If that's the case, and it's a tiny one-off leak, don't sweat it.
Related
Been having a tough time on this one, hope someone can help! New to posting, but have found this to be my go-to site for helping me through my apps.
I have an app that takes a CGImage and copies it to the Photo Library using writeImageToSavedPhotosAlbum:orientation:completionBlock:. Functionally works great, but Instruments seems to be telling me I have a leak. Through trial and error and commenting of code, I've found that this particular line is causing the leak:
[library writeImageToSavedPhotosAlbum:myCGImage
orientation:assetOrientation
completionBlock:^(NSURL *assetURL, NSError *error){
NSLog(#"image copied to album");
}];
That line seems innocuous enough to me, so I'm really not sure why it's causing a problem. Commented out, no leak. Leave it in, I see a leak!
Here's what Instrument shows in Leaked Blocks:
Leaked Object # Address Size Responsible Library Responsible Frame
GeneralBlock-36864, 0x8c77000 36.00 KB MusicLibrary MemNewPtrClear
Here's the stack trace from Instruments, which seems to imply it's related to the photo library indeed:
0 libsystem_c.dylib calloc
1 MusicLibrary MemNewPtrClear
2 MusicLibrary ReadITImageDB
3 MusicLibrary -[MLPhotoLibrary _loadImageLibrary]
4 MusicLibrary -[MLPhotoLibrary albums]
5 PhotoLibrary -[PLPhotoLibrary albums]
6 PhotoLibrary -[PLPhotoLibrary eventAlbumContainingPhoto:]
7 PhotoLibrary -[PLPhotoLibrary pictureWasTakenOrChanged]
8 PhotoLibrary __-[PLAssetsSaver queueJobData:requestEnqueuedBlock:completionBlock:imagePort:previewImagePort:]_block_invoke_2
9 libdispatch.dylib _dispatch_call_block_and_release
10 libdispatch.dylib _dispatch_main_queue_callback_4CF$VARIANT$up
11 CoreFoundation __CFRunLoopRun
12 CoreFoundation CFRunLoopRunSpecific
13 CoreFoundation CFRunLoopRunInMode
14 GraphicsServices GSEventRunModal
15 GraphicsServices GSEventRun
16 UIKit -[UIApplication _run]
17 UIKit UIApplicationMain
18 mogofoto main /Users/Jutsu/Documents/mogofoto2/main.m:14
19 mogofoto start
I do release myCGIImage later, and library as well, and assetOrientation is simply a ALAssetOrientation. Nothing else is custom code, so I'm stumped! (I'd be happy to post my other lines of code surrounding this if that may cause the problem).
Any help is hugely appreciated!!!
I had similar code to yours:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSMutableDictionary *metadata = [[NSMutableDictionary alloc] init];
/* ... set up the metadata */
[library writeImageToSavedPhotosAlbum:image.CGImage metadata:metadata
completionBlock:^(NSURL *assetURL, NSError *error)
{ NSLog(#"assetURL %#", assetURL);
[metadata release];
[library release];
}
];
And I was seeing exactly the same leak as you:
Leaked Object Address Size Responsible Library Responsible Frame
GeneralBlock-36864,0x5066000 36.00 KB MusicLibrary MemNewPtrClear
GeneralBlock-36864,0x4fd3000 36.00 KB MusicLibrary MemNewPtrClear
GeneralBlock-36864,0x4f72000 36.00 KB MusicLibrary MemNewPtrClear
GeneralBlock-36864,0x45ce000 36.00 KB MusicLibrary MemNewPtrClear
with a stack:
0 libsystem_c.dylib calloc
1 MusicLibrary MemNewPtrClear
2 MusicLibrary ReadITImageDB
3 MusicLibrary -[MLPhotoLibrary _loadImageLibrary]
4 MusicLibrary -[MLPhotoLibrary albums]
5 PhotoLibrary -[PLPhotoLibrary albums]
6 PhotoLibrary -[PLPhotoLibrary eventAlbumContainingPhoto:]
7 PhotoLibrary -[PLPhotoLibrary pictureWasTakenOrChanged]
8 PhotoLibrary __-[PLAssetsSaver queueJobData:requestEnqueuedBlock:completionBlock:imagePort:previewImagePort:]_block_invoke_2
9 libdispatch.dylib _dispatch_call_block_and_release
10 libdispatch.dylib _dispatch_main_queue_callback_4CF$VARIANT$up
11 CoreFoundation __CFRunLoopRun
12 CoreFoundation CFRunLoopRunSpecific
13 CoreFoundation CFRunLoopRunInMode
14 GraphicsServices GSEventRunModal
15 GraphicsServices GSEventRun
16 UIKit -[UIApplication _run]
17 UIKit UIApplicationMain
18 myAppName main
19 myAppName start
I can't see anything wrong with the code, but on looking at it again it seemed stupid to be allocing the ALAssetsLibrary and the NSMutableDictionary every time I wanted to write an image. I re-wrote the code to keep hold of them, and removed the release calls from the completion block, and the leak has magically gone away.
I'm not sure if any of that actually helps you very much. But it does make me wonder if there isn't actually a problem in Apple's code, which is only getting triggered in certain circumstances -- certainly I wasn't seeing a leak for every image I was writing, only some of them.
I'm trying to test a Cocos2D app on an iPhone, and get this crash that I copied from the console:
cocos2d: CCSpriteFrameCache: Trying to use file 'heroTestSheet.png' as texture
cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
cocos2d: Couldn't add image:heroTestSheet.png in CCTextureCache
cocos2d: CCSpriteFrameCache: Couldn't load texture
cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
cocos2d: Couldn't add image:heroTestSheet.png in CCTextureCache
cocos2d: CCSpriteFrameCache: Frame 'heroFrame1.png' not found
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'
*** Call stack at first throw:
(
0 CoreFoundation 0x3759dc7b __exceptionPreprocess + 114
1 libobjc.A.dylib 0x32d9bee8 objc_exception_throw + 40
2 CoreFoundation 0x3752a951 -[__NSArrayM insertObject:atIndex:] + 136
3 CoreFoundation 0x3752a8bf -[__NSArrayM addObject:] + 34
4 cocosTests 0x0000ce28 -[HeroClass init] + 1544
5 cocosTests 0x0000304c -[DebugZoneLayer init] + 860
6 cocosTests 0x00074e04 +[CCNode node] + 76
7 cocosTests 0x0000c4e4 -[DebugZoneScene init] + 244
8 cocosTests 0x00074e04 +[CCNode node] + 76
9 cocosTests 0x0000c390 +[DebugZoneScene scene] + 100
10 cocosTests 0x00002540 -[cocosTestsAppDelegate applicationDidFinishLaunching:] + 1028
11 UIKit 0x3592502c -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1200
12 UIKit 0x3591ea78 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 396
13 UIKit 0x358d82e4 -[UIApplication handleEvent:withNewEvent:] + 1476
14 UIKit 0x358d7b1c -[UIApplication sendEvent:] + 68
15 UIKit 0x358d73b4 _UIApplicationHandleEvent + 6824
16 GraphicsServices 0x33e77c88 PurpleEventCallback + 1048
17 CoreFoundation 0x3752f5cb __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 28
18 CoreFoundation 0x3752f589 __CFRunLoopDoSource1 + 164
19 CoreFoundation 0x37521835 __CFRunLoopRun + 580
20 CoreFoundation 0x3752150b CFRunLoopRunSpecific + 226
21 CoreFoundation 0x37521419 CFRunLoopRunInMode + 60
22 UIKit 0x3591d554 -[UIApplication _run] + 548
23 UIKit 0x3591a558 UIApplicationMain + 972
24 cocosTests 0x000020c4 main + 100
25 cocosTests 0x0000205c start + 40
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
Running it in the simulator runs fine, but I still get this message in the console when it starts up "CCSpriteFrameCache: Trying to use file 'heroTestSheet.png' as texture"
I suspect that's where the problem starts. Maybe I'm just understanding how my code for my hero sprite subclass should be written. I thought heroTestSheet.png was the texture it was relying on to split up into other images referencing the plist.
Here's my init in my hero subclass:
-(id) init{
self = [super init];
if (!self) {
return nil;
}
_collisWidthFromCtr = 16;
_collisHeightFromCtr = 16;
_collisPushPointsNums = 5;
_travelRectCenterPoints = [[NSMutableArray alloc] init];
_collisPushPoints = [[NSMutableArray alloc] init];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( _collisWidthFromCtr, _collisHeightFromCtr)] atIndex:0];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( _collisWidthFromCtr, 0)] atIndex:1];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( _collisWidthFromCtr,-_collisHeightFromCtr)] atIndex:2];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( 0, _collisHeightFromCtr)] atIndex:3];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake(-_collisWidthFromCtr, _collisHeightFromCtr)] atIndex:4];
_rectCheckRes = 32;
_speed = 8;
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:#"heroTestSheet.plist"];
_heroSpriteSheet = [CCSpriteBatchNode batchNodeWithFile:#"heroTestSheet.png"];
//[self addChild:_heroSpriteSheet];
NSMutableArray *heroSpriteFlyAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 2; ++i) {
[heroSpriteFlyAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:#"heroFrame%d.png", i]]];
}
CCAnimation *heroSpriteFlyAnim = [CCAnimation animationWithFrames:heroSpriteFlyAnimFrames delay:0.03f];
_heroSprite = [CCSprite spriteWithSpriteFrameName:#"heroFrame1.png"];
_heroSpriteFlyAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:heroSpriteFlyAnim restoreOriginalFrame:NO]];
[_heroSprite runAction:_heroSpriteFlyAction];
[_heroSpriteSheet addChild:_heroSprite];
return self;
}
Please excuse me if I'm being unclear, so let me know any other info I need to provide. Just posting this for now because I don't know where else to start to solve it and what other info I should provide, and it might be obvious to some other cocos devs whats wrong from what I posted. Thanks
The simulator can be more forgiving than the device. Double check that your file name really is "heroTestSheet.png" and not "HeroTestSheet.png" for example. It is case sensitive on your device.
Figured it out.. it was just the heroTestSheet.png it was trying to use was somehow invalid. I exported in an older photoshop, but I'm not really positive what settings it had. I exported it again from a newer photoshop without any color mange settings, and now it works fine!
I think you image was not added on the project.
You must copy your binary to the resource.
select your target and then select the build phases then copy bundle resource
add you image on that content.
I think it will work.
NSURLConnectionDelegate surely reduces the memory consumption and helps to parse the data very fast. I have used the logic from SeismicXML from Apple store and have used to parse the data. But my new concern is whenever I do "build and debug" my code, it runs fine. but when I run the application on its own it does not work. Does any one have any idea why it wont work when I run it on its own. I tried to use "build and analyze" my code but it did not show me any error on my memory management issues.
I did look into the logs of the crash and here is what I receive:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x000000007d89f87d
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Application Specific Information:
objc_msgSend() selector name: release
iPhone Simulator 235, iPhone OS 4.2 (iPhone/8C134)
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x01134a63 objc_msgSend + 23
1 UIKit 0x004ab1e2 -[UITableViewCell removeFromSuperview] + 167
2 UIKit 0x003249d9 -[UIView dealloc] + 340
3 UIKit 0x0032e281 -[UIScrollView dealloc] + 341
4 UIKit 0x003661ce -[UITableView dealloc] + 1085
5 CoreFoundation 0x00ee9a6c CFRelease + 92
6 CoreFoundation 0x00f0eb8d _CFAutoreleasePoolPop + 237
7 QuartzCore 0x00d9a71c run_animation_callbacks(double, void*) + 359
8 QuartzCore 0x00d9a589 CA::timer_callback(__CFRunLoopTimer*, void*) + 157
9 CoreFoundation 0x00fb3fe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
10 CoreFoundation 0x00fb5594 __CFRunLoopDoTimer + 1220
11 CoreFoundation 0x00f11cc9 __CFRunLoopRun + 1817
12 CoreFoundation 0x00f11240 CFRunLoopRunSpecific + 208
13 CoreFoundation 0x00f11161 CFRunLoopRunInMode + 97
14 GraphicsServices 0x01874268 GSEventRunModal + 217
15 GraphicsServices 0x0187432d GSEventRun + 115
16 UIKit 0x002fa42e UIApplicationMain + 1160
17 Tab_Table_Win 0x00001d7c main + 102 (main.m:14)
18 Tab_Table_Win 0x00001d0d start + 53
Thread 1: Dispatch queue: com.apple.libdispatch-manager
0 libSystem.B.dylib 0x94470982 kevent + 10
1 libSystem.B.dylib 0x9447109c _dispatch_mgr_invoke + 215
2 libSystem.B.dylib 0x94470559 _dispatch_queue_invoke +
This is not the issue with NSURLConnection. You're over-releasing some of your UI components (presumably some table or table cell).
Most likely an issue with over releasing your tableview.
Are you using a UITableViewController? If so you should not be releasing the tableview yourself (and it looks like you are) otherwise check where you are alloc'ing/releasing it to make sure you are not calling release more than it is necessary.
Otherwise post your view controller interface declaration, as well as the code where you alloc/access your table view (likely to be your viewDidLoad) and your dealloc method.
#Rog
Here is my code where I am using my UITableViewController and have released the allocated objects. Just FYI, I am using NSOperationQueue to parse my XML file and pull the data and parse it.
#interface TableViewController : UITableViewController
{
IBOutlet UITableView *eTableView;
NSArray *cellNames;
NSMutableArray *listArray;
WinAppDelegate *appDelegate;
}
#property (nonatomic, retain) UITableView *eTableView;
#property (nonatomic, retain) NSArray *cellNames;
#property (nonatomic, retain) NSMutableArray *listArray;
- (void)dealloc
{
[cellNames release];
[eTableView release];
[listArray release];
[super dealloc];
}
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Thread" inManagedObjectContext:managedObjectContext];
That line doesn't seem to work anymore (I'm pretty sure its that line).
I can't seem to work out whats the problem. The application worked perfectly on Xcode with iOS 4.1 and now crashes with this error in the console:
2010-12-07 17:12:27.552 SMSApp[9222:207] +[ persistentStoreCoordinator]: unrecognized selector sent to class 0x5b14580
2010-12-07 17:12:27.553 SMSApp[9222:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[ persistentStoreCoordinator]: unrecognized selector sent to class 0x5b14580'
*** Call stack at first throw:
(
0 CoreFoundation 0x01547be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0169c5c2 objc_exception_throw + 47
2 CoreFoundation 0x015497bb +[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x014b9366 ___forwarding___ + 966
4 CoreFoundation 0x014b8f22 _CF_forwarding_prep_0 + 50
5 CoreData 0x00e6f3ca +[NSEntityDescription entityForName:inManagedObjectContext:] + 42
6 SMSApp 0x000046b9 -[MessagesRootViewController reloadMessages:] + 146
7 SMSApp 0x00004a09 -[MessagesRootViewController viewDidLoad] + 85
8 UIKit 0x0052265e -[UIViewController view] + 179
9 UIKit 0x00520a57 -[UIViewController contentScrollView] + 42
10 UIKit 0x00531201 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
11 UIKit 0x0052f831 -[UINavigationController _layoutViewController:] + 43
12 UIKit 0x00530b4c -[UINavigationController _startTransition:fromViewController:toViewController:] + 524
13 UIKit 0x0052b606 -[UINavigationController _startDeferredTransitionIfNeeded] + 266
14 UIKit 0x00643e01 -[UILayoutContainerView layoutSubviews] + 226
15 QuartzCore 0x010b4451 -[CALayer layoutSublayers] + 181
16 QuartzCore 0x010b417c CALayerLayoutIfNeeded + 220
17 QuartzCore 0x010ad37c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
18 QuartzCore 0x010ad0d0 _ZN2CA11Transaction6commitEv + 292
19 UIKit 0x0047719f -[UIApplication _reportAppLaunchFinished] + 39
20 UIKit 0x00477659 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 690
21 UIKit 0x00481db2 -[UIApplication handleEvent:withNewEvent:] + 1533
22 UIKit 0x0047a202 -[UIApplication sendEvent:] + 71
23 UIKit 0x0047f732 _UIApplicationHandleEvent + 7576
24 GraphicsServices 0x01b2ca36 PurpleEventCallback + 1550
25 CoreFoundation 0x01529064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
26 CoreFoundation 0x014896f7 __CFRunLoopDoSource1 + 215
27 CoreFoundation 0x01486983 __CFRunLoopRun + 979
28 CoreFoundation 0x01486240 CFRunLoopRunSpecific + 208
29 CoreFoundation 0x01486161 CFRunLoopRunInMode + 97
30 UIKit 0x00476fa8 -[UIApplication _run] + 636
31 UIKit 0x0048342e UIApplicationMain + 1160
32 SMSApp 0x000025c4 main + 102
33 SMSApp 0x00002555 start + 53
)
terminate called after throwing an instance of 'NSException'
Any idea where this error is coming from or what is causing it?
Just to let you know as well, upgrading to XCode with iOS 4.2 caused some of the files to be deleted from my project. I don't know why this was, whether it was because they were linked files and not actually in the folder I dunno.
Any ideas?
Thanks
// EDIT
This method is in the AppDelegate:
- (NSManagedObjectContext *)managedObjectContext {
if (managedObjectContext_ != nil) {
return managedObjectContext_;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
managedObjectContext_ = [[NSManagedObjectContext alloc] init];
[managedObjectContext_ setPersistentStoreCoordinator:coordinator];
}
return managedObjectContext_;
}
// EDIT AGAIN
- (void)reloadMessages:(NSNotification *)notification {
NSLog(#"RECIEVED NEW MESSAGES TO MessagesRootViewController");
NSLog(#"%#",managedObjectContext);
// we need to get the threads from the database...
NSFetchRequest *theReq = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Thread" inManagedObjectContext:self.managedObjectContext];
[theReq setEntity:entity];
threads = [NSArray arrayWithArray:[managedObjectContext executeFetchRequest:theReq error:nil]];
[self.tableView performSelectorOnMainThread:#selector(reloadData) withObject:nil waitUntilDone:NO];
if(notification != nil){ // if its been caused by a notification
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"New Message" message:#"A new message has been received" delegate:nil cancelButtonTitle:#"Thanks" otherButtonTitles:nil];
[alert performSelectorOnMainThread:#selector(show) withObject:nil waitUntilDone:NO];
[alert release];
}
}
// EDIT 3
If I put this code in the applicationDidFinishLoading of my app delegate it works fine!
NSFetchRequest *theReq = [[NSFetchRequest alloc] init];
NSEntityDescription *theEntity = [NSEntityDescription entityForName:#"Thread" inManagedObjectContext:self.managedObjectContext];
[theReq setEntity:theEntity];
NSArray *theThreads = [NSArray arrayWithArray:[self.managedObjectContext executeFetchRequest:theReq error:nil]];
After having a quick look at your code I think I found a couple of parts that needed attention. I'll try and break them down below:
SMSAppAppDelegate
1) Notice that in your interface file, you declare your CoreData variables with an underscore at the end of the variable name. Then you create properties for each of the ivar without the underscore. That is all fine as long as you #synthesize them making the correct assignment, which seems to be missing from your implementation:
#synthesize managedObjectContext=managedObjectContext_;
#synthesize managedObjectModel=managedObjectModel_;
#synthesize persistentStoreCoordinator=persistentStoreCoordinator_;
DownloadContacts
1) In this class you are calling the managedObjectContext directly through the variable. I wouldn't recommend that but this is not your actual problem. Notice that you release the managedObjectContext on dealloc even though you have no ownership of it!
2) What I would do in this case is declare a property for the context and always access it via the property. Also if you rename your instance variable to include an underscore at the end you are minimising your chances of accessing it directly (i.e. without using self.) and it will make it easier for you to find where in this class you are actually doing that (there are a couple of places from memory).
So in your interface file, rename managedObjectContext ivar and declare a property:
NSManagedObjectContext *managedObjectContext_;
...
#property (nonatomic, retain) NSManagedObjectContext managedObjectContext;
And don't forget to make the assignment on #sythesize and release on dealloc, since you are using a retain property:
#synthesize managedObjectContext=managedObjectContext_;
...
[managedObjectContext_ release];
Then if you try and compile you will get two or three errors of unrecognised instance variable which is where you have to go and change it to self.managedObjectContext
MessagesRootViewController
And finally I'd recommend you go through the same process in your MessagesRootViewController but this one should still work fine as is!
See how you go and let me know if any of the above is not clear!
Cheers,
Rog
I'm assuming you're doing something like:
[ClassName persistentStoreCoordinator]
Make sure ClassName is defined and has the persistentStoreCoordinator class method. Perhaps the file that did these things got deleted?
Matt
Your database might be corrupted, try resetting the iOS simulator
by clicking on iOS Simulator>Reset contents and settings.
Edit:
It looks like you're trying to call a selector that doesn't exist. Try figuring out which files were deleted, as it seems like you have a method that is called that can't be found at runtime. Did your core data classes get erased, maybe?
I grabbed the crash log from the iPhone:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000c
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x30011940 objc_msgSend + 20
1 CoreFoundation 0x30235f1e CFRelease + 98
2 UIKit 0x308f4974 -[UIImage dealloc] + 36
3 CoreFoundation 0x30236b72 -[NSObject release] + 28
4 UIKit 0x30a00298 FlushNamedImage + 64
5 CoreFoundation 0x30250a20 CFDictionaryApplyFunction + 124
6 UIKit 0x30a0019c _UISharedImageFlushAll + 196
7 UIKit 0x30a00730 +[UIImage(UIImageInternal) _flushCacheOnMemoryWarning:] + 8
8 Foundation 0x3054dc7a _nsnote_callback + 178
9 CoreFoundation 0x3024ea52 _CFXNotificationPostNotification + 298
10 Foundation 0x3054b854 -[NSNotificationCenter postNotificationName:object:userInfo:] + 64
11 Foundation 0x3054dbba -[NSNotificationCenter postNotificationName:object:] + 14
12 UIKit 0x30a00708 -[UIApplication _performMemoryWarning] + 60
13 UIKit 0x30a006a0 -[UIApplication _receivedMemoryNotification] + 128
14 UIKit 0x30a005d0 _memoryStatusChanged + 56
15 CoreFoundation 0x30217410 __CFNotificationCenterDarwinCallBack + 20
16 CoreFoundation 0x3020d0aa __CFMachPortPerform + 72
17 CoreFoundation 0x30254a70 CFRunLoopRunSpecific + 2296
18 CoreFoundation 0x30254164 CFRunLoopRunInMode + 44
19 GraphicsServices 0x3204529c GSEventRunModal + 188
20 UIKit 0x308f0374 -[UIApplication _run] + 552
21 UIKit 0x308eea8c UIApplicationMain + 960
...
...
From my previous question, Can somebody give me a hand about this stacktrace in iPhone app?, I have changed my codes mainly around UIImage part. I now use [[UIImage alloc] initWithContentsOfFile ... ]. No more [UIImage imageNamed: ... ] or the like. The portion is below.
//this is a method of a subclass of UIImageView.
- (void) reviewImage: (bool) review{
NSString* st;
if (review){
NSString* origin = [NSString stringWithString: [[ReviewCardManager getInstance] getCardImageString:chosenIndex]];
NSString* stt = [origin substringToIndex: [origin length]-4];
st = [[NSString alloc] initWithString: stt];
if (myImageFlipped == nil)
myImageFlipped = [[UIImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:st ofType:#"png"]];
[self setImage:myImageFlipped];
if (notRotated){
self.transform = CGAffineTransformRotate(self.transform, [MyMath radf:rotate]);
notRotated = false;
}
}else{
st = [[NSString alloc] initWithFormat:#"sc%d", chosenNumber];
if (myImage == nil)
myImage = [[UIImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:st ofType:#"png"]];
[self setImage:myImage];
if (notRotated){
self.transform = CGAffineTransformRotate(self.transform, [MyMath radf:rotate]);
notRotated = false;
}
}
[st release];
}
I also have the UIImage already retained in the property.
#property (nonatomic, retain) UIImage* myImage, *myImageFlipped;
Memory Leaks have also been taken cared of. These variables are release in dealloc method.
I thought that I have successfully killed the bug, but it seems that I still have a rare occuring bug problem.
Based on the crash log, my application yells out "performMemoryWarning". I am just "alloc"-ing 13 .png images with the size 156 x 272. I'm confused. Those images shouldn't take that much memory to the point that it exceeds iPhone's RAM. Or is there something I am overlooking? Please advise.
To help you with memory issues and UIImages, you might want to use the imageNamed convience method of UIImage, from the docs:
This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object.
Alternatively, you might want to go this route if you still run into memory issues after switching to UIImage imageNamed, because there are some downsides to using the convinience method.
The problem is solved. I forgot to change UIImage at one place. Now, all UIImages are truly "alloc", no more autorelease.
FYI, if you are using [UIImage imageNamed: ... ], use "Simulate Memory Warning" on iPhone Simulator to see whether you are having a problem with it when the real device is low on memory.