[CFNumber release]: message sent to deallocated instance - iphone

The code below returns the following error when I log/request values from the History Core Data object:
-[CFNumber release]: message sent to deallocated instance 0x17ea2a90
I originally thought there was an issue elsewhere and have spent countless hours attempting to debug this to no luck. After further testing, I have pinpointed the crash to requesting certain values from the History Core Data object. Can anyone see any issues to why the object values are being deallocated?
[[DocumentHandler sharedDocumentHandler] performWithDocument:^(UIManagedDocument *document) {
if(!self.document) {
self.document = document;
}
__block NSString *identifier = [[NSUserDefaults standardUserDefaults] objectForKey:kUserDefaultsUserIdentifier];
[self.document.managedObjectContext performBlock:^{
// Create history object
History *history = [NSEntityDescription insertNewObjectForEntityForName:#"History"
inManagedObjectContext:self.document.managedObjectContext];
history.identifier = identifier;
history.followers = [NSNumber numberWithInteger:53];
history.following = [NSNumber numberWithInteger:53];
history.newFollowers = [NSNumber numberWithInteger:53];
history.unfollowers = [NSNumber numberWithInteger:53];
history.fans = [NSNumber numberWithInteger:53];
history.mutualFriends = [NSNumber numberWithInteger:53];
history.nonFollowers = [NSNumber numberWithInteger:53];
[self.document saveToURL:self.document.fileURL forSaveOperation:UIDocumentSaveForOverwriting completionHandler:^(BOOL success) {
// Fetch previous records
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:#"History"];
request.predicate
= [NSPredicate predicateWithFormat:#"identifier == %#", identifier];
NSError *error = nil;
NSArray *records = [self.document.managedObjectContext executeFetchRequest:request error:&error];
[records enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSLog(#"%#", [(History *)obj newFollowers]); // Crash takes place here
}];
}];
}];
}];
More logs with an exception breakpoint enabled:
(lldb) bt
* thread #1: tid = 0x28b70, 0x3b5787fa libobjc.A.dylib`objc_release + 10, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
frame #0: 0x3b5787fa libobjc.A.dylib`objc_release + 10
frame #1: 0x3b578022 libobjc.A.dylib`(anonymous namespace)::AutoreleasePoolPage::pop(void*) + 358
frame #2: 0x311b4298 CoreFoundation`_CFAutoreleasePoolPop + 16
frame #3: 0x3127533e CoreFoundation`__NSArrayEnumerate + 614
frame #4: 0x31216012 CoreFoundation`-[NSArray enumerateObjectsWithOptions:usingBlock:] + 62
frame #5: 0x000eae26 Twitter Followers`__71-[MainViewController updateCurrentRecordAndTableHeaderForUpdateAction:]_block_invoke_2(.block_descriptor=0x15e58080, success='\x01') + 678 at MainViewController.m:671
frame #6: 0x3ba65bea libdispatch.dylib`_dispatch_barrier_sync_f_slow_invoke + 66
frame #7: 0x3ba600ee libdispatch.dylib`_dispatch_client_callout + 22
frame #8: 0x3ba629a8 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 268
frame #9: 0x3124b5b8 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
frame #10: 0x31249e84 CoreFoundation`__CFRunLoopRun + 1308
frame #11: 0x311b4540 CoreFoundation`CFRunLoopRunSpecific + 524
frame #12: 0x311b4322 CoreFoundation`CFRunLoopRunInMode + 106
frame #13: 0x35eeb2ea GraphicsServices`GSEventRunModal + 138
frame #14: 0x33a6b1e4 UIKit`UIApplicationMain + 1136

According to the Transitioning to ARC Release Notes:
To allow interoperation with manual retain-release code, ARC imposes a constraint on method naming:
You cannot give an accessor a name that begins with new. This in turn means that you can’t, for example, declare a property whose name begins with new unless you specify a different getter:
// Won't work:
#property NSString *newTitle;
// Works:
#property (getter=theNewTitle) NSString *newTitle;
Bottom line, methods that start with new are assumed to return an object that ARC is responsible for managing and releasing (but this isn't the case here). I'd suggest just changing your property so that it doesn't start with new to avoid any confusion.

Related

Frequently asihttprequest runrequests crash

thread #7: tid = 0x2403, 0x351b9010 libsystem_kernel.dylibmach_msg_trap + 20
frame #0: 0x351b9010 libsystem_kernel.dylibmach_msg_trap + 20
frame #1: 0x351b920c libsystem_kernel.dylibmach_msg + 56
frame #2: 0x33672422 CoreFoundationCFRunLoopServiceMachPort + 126
frame #3: 0x3367115a CoreFoundation__CFRunLoopRun + 882
frame #4: 0x335f44dc CoreFoundationCFRunLoopRunSpecific + 300
frame #5: 0x335f43a4 CoreFoundationCFRunLoopRunInMode + 104
frame #6: 0x30e8cbc8 Foundation+[NSURLConnection(Loader) resourceLoadLoop:] + 308
frame #7: 0x30e8ca90 Foundation-[NSThread main] + 72
frame #8: 0x30f205a0 Foundation_NSThread__main + 1048
frame #9: 0x3709bc1c libsystem_c.dylib`_pthread_start + 320
I am not using ASINetworkQueue and using through an array of urls, and I have implemented the requestFinished: method, that gets called fine. I got received crash when request is not responded.
Could you please some one help me out ?
Sample Code snippet :
Class A (Wrapper class extends ASIHTTPRequest) :
ASIHTTPRequest *httpRequest;
- (id)initWithURL:(NSString *)anURL errorInfo:(NSError **)error {
if (self = [super init]) {
NSURL *httpURL = [NSURL URLWithString:anURL];
httpRequest = [self createASIRequest:httpURL];
didFinishSelector = #selector(requestFinished:);
didFailSelector = #selector(requestFailed:);
return self;
}
}
- (void)dealloc {
if (httpRequest) {
[httpRequest clearDelegatesAndCancel];
[httpRequest release];
httpRequest = nil;
}
[super dealloc];
}
- (ASIHTTPRequest *)createASIRequest:(NSURL *)url {
ASIHTTPRequest *request = [[ASIHTTPRequest requestWithURL:url] retain];
request.delegate = self;
return request;
}
Class B :
Request in loop:
Class A *d = [[Class A alloc] initWithURL:url errorInfo:&pError];
d.didFinishSelector = #selector(responseHandler:);
d.didFailSelector = #selector(responseHandler:);
The delegate methods are being called after view controller has been released. So, needs to clean all delegates before releasing the view controller.This works for me.

Memory issue in objective c

My application is attempting to use a zombie instance of something, though i have no idea where the problem is. the exception consistently occurs when invoking (IBAction)addTag:sender.
my stack trace is below:
2012-03-12 17:06:45.935 FavoriteTwitterSearches[3636:f803] -[__NSCFString addTag:]: unrecognized selector sent to instance 0x6a30d90
2012-03-12 17:06:45.943 FavoriteTwitterSearches[3636:f803] CRASH: -[__NSCFString addTag:]: unrecognized selector sent to instance 0x6a30d90
2012-03-12 17:06:45.947 FavoriteTwitterSearches[3636:f803] Stack Trace: (
0 CoreFoundation 0x013bc06e __exceptionPreprocess + 206
1 libobjc.A.dylib 0x0154dd0a objc_exception_throw + 44
2 CoreFoundation 0x013bdced -[NSObject doesNotRecognizeSelector:] + 253
3 CoreFoundation 0x01322f00 ___forwarding___ + 432
4 CoreFoundation 0x01322ce2 _CF_forwarding_prep_0 + 50
5 CoreFoundation 0x013bdec9 -[NSObject performSelector:withObject:withObject:] + 73
6 UIKit 0x000165c2 -[UIApplication sendAction:to:from:forEvent:] + 96
7 UIKit 0x0001655a -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8 UIKit 0x000bbb76 -[UIControl sendAction:to:forEvent:] + 66
9 UIKit 0x000bc03f -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 503
10 UIKit 0x000bb2fe -[UIControl touchesEnded:withEvent:] + 549
11 UIKit 0x0003ba30 -[UIWindow _sendTouchesForEvent:] + 513
12 UIKit 0x0003bc56 -[UIWindow sendEvent:] + 273
13 UIKit 0x00022384 -[UIApplication sendEvent:] + 464
14 UIKit 0x00015aa9 _UIApplicationHandleEvent + 8196
15 GraphicsServices 0x012a6fa9 PurpleEventCallback + 1274
16 CoreFoundation 0x013901c5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
17 CoreFoundation 0x012f5022 __CFRunLoopDoSource1 + 146
18 CoreFoundation 0x012f390a __CFRunLoopRun + 2218
19 CoreFoundation 0x012f2db4 CFRunLoopRunSpecific + 212
20 CoreFoundation 0x012f2ccb CFRunLoopRunInMode + 123
21 GraphicsServices 0x012a5879 GSEventRunModal + 207
22 GraphicsServices 0x012a593e GSEventRun + 114
23 UIKit 0x00013a9b UIApplicationMain + 1175
24 FavoriteTwitterSearches 0x00001fab main + 187
25 FavoriteTwitterSearches 0x00001ee5 start + 53
26 ??? 0x00000001 0x0 + 1
)
objc[3636]: EXCEPTIONS: finishing handler
Support Files/Main.m:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
void uncaughtExceptionHandler(NSException *exception);
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal;
#try {
retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
#catch (NSException *exception) {
NSLog(#"CRASH: %#", exception);
NSLog(#"Stack Trace: %#", [exception callStackSymbols]);
}
#finally {
[pool release];
}
return retVal;
}
Controller.m
#import "Controller.h"
#implementation Controller
- (id)init
{
if (self != nil)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dir = [paths objectAtIndex:0];
filePath = [[NSString alloc] initWithString:[dir stringByAppendingPathComponent:#"tagsIndex.plist"]];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:filePath] == NO)
{
tags = [[NSMutableDictionary alloc] init];
}
else
{
tags = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
}
buttons = [[NSMutableArray alloc] init];
infoButtons = [[NSMutableArray alloc] init];
}
return self;
}
- (void)awakeFromNib
{
for (NSString *title in tags)
[self addNewButtonWithTitle:title];
}
- (void)refreshList
{
for (UIButton *button in scrollView.subviews)
[button removeFromSuperview];
[infoButtons removeAllObjects];
float buttonOffset = BUTTON_SPACING;
for (UIButton *button in buttons)
{
CGRect buttonFrame = button.frame;
buttonFrame.origin.x = BUTTON_SPACING;
buttonFrame.origin.y = buttonOffset;
buttonFrame.size.width = scrollView.frame.size.width - BUTTON_SPACING - BUTTON_HEIGHT;
buttonFrame.size.height = BUTTON_HEIGHT;
button.frame = buttonFrame;
UIButton *infobutton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButtons addObject:infobutton];
buttonFrame = infobutton.frame;
buttonFrame.origin.x = scrollView.frame.size.width - BUTTON_SPACING - SCROLLBAR_WIDTH;
buttonFrame.origin.y = buttonOffset;
infobutton.frame = buttonFrame;
[infobutton
addTarget:self action:#selector(infoButtonTouched:)
forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:infobutton];
buttonOffset += BUTTON_HEIGHT + BUTTON_SPACING;
}
}
- (void)infoButtonTouched:sender
{
int index = [infoButtons indexOfObject:sender];
NSString *key = [[buttons objectAtIndex:index] titleLabel].text;
tagField.text = key;
NSString *value = [tags valueForKey:key];
queryField.text = value;
}
- (IBAction)addTag:sender
{
[tagField resignFirstResponder];
[queryField resignFirstResponder];
NSString *key = tagField.text;
NSString *value = queryField.text;
if (value.length == 0 || key.length == 0) return;
if ([tags valueForKey:key] == nil)
[self addNewButtonWithTitle:key];
[tags setValue:value forKey:key];
tagField.text = nil;
queryField.text = nil;
[tags writeToFile:filePath atomically:NO];
}
- (IBAction)clearTags:sender
{
[tags removeAllObjects];
[tags writeToFile:filePath atomically:NO];
[buttons removeAllObjects];
[self refreshList];
}
- (void)addNewButtonWithTitle:(NSString *)title
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:title forState:UIControlStateNormal];
[button
addTarget:self action:#selector(buttonTouched:)
forControlEvents:UIControlEventTouchUpInside];
[buttons addObject:button];
[buttons sortUsingSelector:#selector(compareButtonTitles:)];
[self refreshList];
CGSize contentSize = CGSizeMake(
scrollView.frame.size.width,
buttons.count * (BUTTON_HEIGHT + BUTTON_SPACING) + BUTTON_SPACING);
[scrollView setContentSize:contentSize];
}
- (void)buttonTouched:sender
{
NSString *key = [sender titleLabel].text;
NSString *search = [[tags valueForKey:key]
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *urlString = [NSString stringWithFormat:
#"http://search.twitter.com/search?q=%#", search];
NSURL *url = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:url];
}
- (void)dealloc
{
[filePath release];
[tags release];
[infoButtons release];
[buttons release];
[super dealloc];
}
#end
#implementation UIButton (sorting)
- (NSComparisonResult)compareButtonTitles:(UIButton *)button
{
return [self.titleLabel.text caseInsensitiveCompare:button.titleLabel.text];
}
#end
[__NSCFString addTag:]: unrecognized selector sent to instance says thay you are calling method addTag: on an instance of type NSString.
Check to what object and how is your IBAction connected in your xib. If everything is okey, try to clean your project, reset your simulator, and then try it again.
EDIT: please, add a NSLog into your dealloc to check if your controller has not been deallocated.
It sounds like most likely a Controller object is getting deallocated prematurely. It's not possible from the code you've posted to tell where it's happening, but you should be able to track it down with Instruments (zombies and malloc stack logging in particular). Or, if Controller isn't used in a lot of places†, it might be quicker just to look there and see if you're mistakenly autoreleasing it.
†For an object called something like "Controller", I wouldn't bet on it, but it's worth mentioning and being able to easily track the life cycle of objects is a great incentive to reduce coupling in your program designs.

CoreLocation 0x34456f78 -[CLLocationManager onClientEventRegistered:] + 384

I am facing this error, I want to know where I am wrong.
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x80000008
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x34499c98 objc_msgSend + 16
1 CoreLocation 0x34456f78 -[CLLocationManager onClientEventRegistered:] + 384
2 CoreLocation 0x34457f42 -[CLLocationManager onClientEvent:supportInfo:] + 46
3 CoreLocation 0x34455a64 OnClientEvent + 16
4 CoreLocation 0x3445178a CLClientInvokeCallback(__CLClient*, CLClientEvent, __CFDictionary const*) + 46
5 CoreLocation 0x344528cc CLClientHandleDaemonDataRegistration(__CLClient*, CLDaemonCommToClientRegistration const*, __CFDictionary const*) + 700
6 CoreLocation 0x34453d50 CLClientHandleDaemonData(__CFMessagePort*, long, __CFData const*, void*) + 220
7 CoreFoundation 0x3094e706 __CFMessagePortPerform + 242
8 CoreFoundation 0x30957a90 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 20
9 CoreFoundation 0x30959838 __CFRunLoopDoSource1 + 160
10 CoreFoundation 0x3095a606 __CFRunLoopRun + 514
11 CoreFoundation 0x308eaebc CFRunLoopRunSpecific + 224
12 CoreFoundation 0x308eadc4 CFRunLoopRunInMode + 52
13 GraphicsServices 0x30269418 GSEventRunModal + 108
14 GraphicsServices 0x302694c4 GSEventRun + 56
15 UIKit 0x30a10d62 -[UIApplication _run] + 398
16 UIKit 0x30a0e800 UIApplicationMain + 664
17 ProjectOne 0x00002918 main (main.m:14)
18 ProjectOne 0x000028cc start + 32
My code :
Start Location :
-(void)startLocationTracing
{
self.TlocationManager = [[CLLocationManager alloc] init];//allocate memeory to locationmanager
self.TlocationManager.desiredAccuracy = kCLLocationAccuracyBest; //Be as accurate as possible
self.TlocationManager.distanceFilter = kCLLocationAccuracyBest;
self.TlocationManager.delegate = self;
[self.TlocationManager startUpdatingLocation];
}
Delegate Method :
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
lat = [NSString stringWithFormat:#"%3.5f",
newLocation.coordinate.latitude];
lng = [NSString stringWithFormat:#"%3.5f",
newLocation.coordinate.longitude];
CLLocation *loc_old = [[CLLocation alloc] initWithLatitude:oldLocation.coordinate.latitude longitude:oldLocation.coordinate.longitude];
CLLocation *loc_new = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];
//get the current distance from the old distance
CLLocationDistance dist = [loc_old distanceFromLocation:loc_new];
// test the age of the location measurement to determine if the measurement is cached
// in most cases you will not want to rely on cached measurement
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 5.0)
{
NSLog(#":::::::Location age is greate then 5.0 ::::::::");
[loc_old release];
[loc_new release];
return;
}
float dist_ = (float)dist;//distance in float
NSLog(#"%f", dist_);
[loc_old release];
[loc_new release];
NSString *str_LastLat = [NSString stringWithFormat:#"%#", [[NSUserDefaults standardUserDefaults] valueForKey:#"LastLat"]];
NSString *str_LastLong = [NSString stringWithFormat:#"%#", [[NSUserDefaults standardUserDefaults] valueForKey:#"LastLong"]];
if(([str_LastLat isEqualToString:lat]) && ([str_LastLong isEqualToString:lng]))
{
//if same lat and long arrives then do not save in the database
NSLog(#"old and new location are same");
}
else
{
if((newLocation.horizontalAccuracy > 0 ) || (newLocation.verticalAccuracy > 0) ){
[self stopTracingLocations];//to stop location services after the data is sent to
objGlobal = [[Global alloc] init];
[objGlobal postLocateValue:lat :lng type:#"TRACING"]; // WCF HIT
[objGlobal release];
}
}
}
Stop Location :
-(void)stopTracingLocations
{
[self.TlocationManager stopUpdatingLocation];
self.TlocationManager.delegate = nil;
if(self.TlocationManager){
[self.TlocationManager release];
}
}
Well it could be due to the fact you are leaking/assining incorectly"
-(void)startLocationTracing {
self.TlocationManager = [[[CLLocationManager alloc] init] autorelease];//allocate memeory to locationmanager
self.TlocationManager.desiredAccuracy = kCLLocationAccuracyBest; //Be as accurate as possible
self.TlocationManager.distanceFilter = kCLLocationAccuracyBest;
self.TlocationManager.delegate = self;
[self.TlocationManager startUpdatingLocation];
}
-(void)stopTracingLocations {
[self.TlocationManager stopUpdatingLocation];
self.TlocationManager.delegate = nil;
self.TlocationManager = nil;
}
I had the same error. It turns out I was allocating the location manager twice. You might want to see if you're doing that somehow.
It happened to me because I had a sub class calling a super method on init. That super.init allocated a location manager. I forgot about that and allocated it again in the sub classing class.

Abort on iPhone simulator

I am receiving an SIGABRT error on the last line of this code loginButton.enabled = YES;. It was working this morning and now this error comes up.
-(IBAction)login:(id)sender
{
UIButton *loginButton = (UIButton *)sender;
loginButton.enabled = NO;
NSString *filePath = [self dataFilePath];
if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
NSString *nameString = [[NSString alloc] init];
NSString *contactIdString = [[NSString alloc] init];
NSString *genderString = [[NSString alloc] init];
NSString *contactTypeString = [[NSString alloc] init];
nameString = [array objectAtIndex:0];
contactIdString = [array objectAtIndex:1];
genderString = [array objectAtIndex:2];
contactTypeString = [array objectAtIndex:3];
self.name = nameString;
self.contactId = contactIdString;
self.gender = genderString;
self.contactType = contactTypeString;
[self.userArray removeAllObjects];
[self performSelectorInBackground:#selector(sendData) withObject:nil];
[nameString release];
[contactIdString release];
[genderString release];
[contactTypeString release];
UIBarButtonItem *logoutButton = [[UIBarButtonItem alloc] initWithTitle:#"Logout" style:UIBarButtonItemStylePlain target:self action:#selector(logout:)];
//[logoutButton setTitle:#"Logout"];
[[self navigationItem] setRightBarButtonItem:logoutButton];
[logoutButton release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"New User" message:#"It seems you have not used FaceDirectory before, please go to My Details and fill out the information then click save." delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
loginButton.enabled = YES;
}
Here is the error dump.
2011-08-12 11:41:56.700 FaceConnect[1651:207] Reachability Flag Status: -R ------- networkStatusForFlags
2011-08-12 11:41:59.247 FaceConnect[1651:207] selected first row
2011-08-12 11:42:02.344 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7a0cf10 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.344 FaceConnect[1651:207] -[__NSCFData setEnabled:]: unrecognized selector sent to instance 0x6f4b820
2011-08-12 11:42:02.344 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7a108b0 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.344 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e06e70 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.344 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e06220 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.345 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e06ca0 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.345 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e068c0 of class NSURL autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.345 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e061c0 of class NSMutableURLRequest autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.345 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e069e0 of class NSCFString autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.345 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e06b30 of class NSCFString autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.345 FaceConnect[1651:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData setEnabled:]: unrecognized selector sent to instance 0x6f4b820' *** Call stack at first throw: (
0 CoreFoundation 0x0249d919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x025eb5de objc_exception_throw + 47
2 CoreFoundation 0x0249f42b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0240f116 ___forwarding___ + 966
4 CoreFoundation 0x0240ecd2_CF_forwarding_prep_0 + 50
5 FaceConnect 0x0000a7ea -[HubViewController login:] + 1802
6 UIKit 0x00123e14 -[UIApplication sendAction:to:from:forEvent:] + 119
7 UIKit 0x0032b14b-[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156
8 UIKit 0x00123e14 -[UIApplication sendAction:to:from:forEvent:] + 119
9 UIKit 0x001ad6c8 -[UIControlsendAction:to:forEvent:] + 67
10 UIKit 0x001afb4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] +527
11 UIKit 0x001ae6f7 -[UIControltouchesEnded:withEvent:] + 458
12 UIKit 0x001472ff -[UIWindow _sendTouchesForEvent:] + 567
13 UIKit 0x001291ec -[UIApplication sendEvent:] + 447
14 UIKit 0x0012dac4 _UIApplicationHandleEvent + 7495
15 GraphicsServices 0x02924afa PurpleEventCallback + 1578
16 CoreFoundation 0x0247edc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__+ 52
17 CoreFoundation 0x023df737__CFRunLoopDoSource1 + 215
18 CoreFoundation 0x023dc9c3 __CFRunLoopRun + 979
19 CoreFoundation 0x023dc280 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x023dc1a1 CFRunLoopRunInMode + 97
21 GraphicsServices 0x029232c8 GSEventRunModal + 217
22 GraphicsServices 0x0292338d GSEventRun + 115
23 UIKit 0x00131b58 UIApplicationMain + 1160
24 FaceConnect 0x00001ac9 main + 121
25 FaceConnect 0x00001a45 start + 53
26 ??? 0x00000001 0x0 + 1 )
2011-08-12 11:42:02.346 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x7e06a40 of class NSCFString autoreleased with no pool in place - just leaking
2011-08-12 11:42:02.346 FaceConnect[1651:6b07] *** __NSAutoreleaseNoPool(): Object 0x6f4c0c0 of class NSCFString autoreleased with no pool in place - just leaking terminate called after throwing an instance of 'NSException' Current language: auto; currently objective-c
I have just checked it on my iPhone, and the application does not crash. It only happens on the simulator.
-(IBAction)login:(id)sender {
[(UIButton*) sender setEnabled:NO];
if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
NSString* name = [array objectAtIndex:0];
NSString* contactId = [array objectAtIndex:1]; // depends if it is an integer then use int
NSString* gender = [array objectAtIndex:2];
NSString* contactType = [array objectAtIndex:3];
//[self.userArray removeAllObjects]; // what is your user array and why you are removing all the objects
// i could not find where you are setting the value for userArray
[self.userArray arrayWithObjects:self.name, self.contactId, self.gender,self.contactType, nil];
[self performSelectorInBackground:#selector(sendData) withObject:nil];
/*if (loginButton.selected == NO) {
// Represents user needs to login. Code for login user.
}else
{
[loginButton setTitle:#"Logout"];
}
// toggle the login/logout states.
loginButton.selected = !loginButton.selected;*/
UIBarButtonItem *logoutButton = [[UIBarButtonItem alloc] initWithTitle:#"Logout" style:UIBarButtonItemStylePlain target:self action:#selector(logout:)];
//[logoutButton setTitle:#"Logout"];
[[self navigationItem] setRightBarButtonItem:logoutButton];
[logoutButton release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"New User" message:#"It seems you have not used FaceDirectory before, please go to My Details and fill out the information then click save." delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
}
[(UIButton*) sender setEnabled:YES];
}
i could not find where you are setting the value for userArray and so i thought i think you are binding the info to userArray and sending
-(id)sendData{
//Do whatever you want to do with userArray
}
-(void)viewDidUnLoad{
self.userarray = nil;
[super viewDidlUnload];
}
-(void)dealloc{
[userArray release];
[super dealloc];
}
You create an empty strings with alloc/init, and then you change them to value returned by objectAtIndex:. This causes the pointer to point to an autoreleased value. After you release your strings, the application will crash because retain count will become less than zero.
I guess the error is propagating from FaceConnect. Please check, it's showing a lot of leaks and warnings.

tableView crashes when going back from detail view iphone

in my application i have a table view and a detail view. The table view is populated from a database query. I have this database methods in the viewDidLoad method (i don't know where else to put it) Then i have the [self.tableView reload] method in the viewWillAppear method. The problem is that when i go back from the detail view to the table view and click the same element (in the table view) the application crashes. I guess it is because the database methods are still running when i come back from the detail view and i click on a cell. So the data in the table view is never reloaded. Do you guys have any idea on how to fix this?
*EDIT:
*Here's the code from the database, i use it to populate the table view:*
- (void)viewDidLoad
{
//Convert the course id to string
NSString *selectedCategoryIdConverted = [NSString stringWithFormat:#"%d", self.selectedCategory._id];
NSMutableArray *tempArray = [[NSMutableArray alloc]init];
// Set up sqlite statement
sqlite3_stmt *dbStatement = nil;
NSString *sqlQuery = [NSString stringWithFormat:#"SELECT co.name, co.id, o.location FROM course as co JOIN categories as ca JOIN occasions as o WHERE co.catID = ca.id AND co.catID = %i AND o.courseID = co.id", self.selectedCategory._id];
//Convert the query string to const char
const char *sqlQueryConverted =[sqlQuery UTF8String];
int prepareSqlQuery = sqlite3_prepare_v2( [[DatabaseController sharedDatabaseController] getDb], sqlQueryConverted, -1, &dbStatement, NULL);
//Run the query
while ( sqlite3_step(dbStatement) == SQLITE_ROW )
{
const char *name = (const char *)sqlite3_column_text(dbStatement, 0);
int courseId = sqlite3_column_int(dbStatement, 1);
const char *location = (const char *)sqlite3_column_text(dbStatement, 2);
//Convert the returnedElement char to string
NSString *nameConverted = [[[NSString alloc] initWithUTF8String:name] autorelease];
NSString *locationConverted = [[[NSString alloc] initWithUTF8String:location] autorelease];
Course *course = [[Course alloc] initWithName:nameConverted _id:courseId location:locationConverted];
[tempArray addObject:course];
}
self.courses = tempArray;
[super viewDidLoad];
}
EDIT: I noticed that when i go back to the table view, the app won't crash if i click on the next element, but if i click on the previous element (row) in the table view the app crashes.
EDIT: I changed the code to the viewDidAppear method and fixed memory leaking. self.courses is (nonatomic, retain) here's the code:
- (void)viewWillAppear:(BOOL)animated
{
//Convert the course id to string
//NSString *selectedCategoryIdConverted = [NSString stringWithFormat:#"%d", self.selectedCategory._id];
NSMutableArray *tempArray = [[NSMutableArray alloc]init];
// Set up sqlite statement
sqlite3_stmt *dbStatement = nil;
NSString *sqlQuery = [NSString stringWithFormat:#"SELECT co.name, co.id, o.location FROM course as co JOIN categories as ca JOIN occasions as o WHERE co.catID = ca.id AND co.catID = %i AND o.courseID = co.id", self.selectedCategory._id];
//Convert the query string to const char
const char *sqlQueryConverted =[sqlQuery UTF8String];
int prepareSqlQuery = sqlite3_prepare_v2( [[DatabaseController sharedDatabaseController] getDb], sqlQueryConverted, -1, &dbStatement, NULL);
//Run the query
while ( sqlite3_step(dbStatement) == SQLITE_ROW )
{
const char *name = (const char *)sqlite3_column_text(dbStatement, 0);
int courseId = sqlite3_column_int(dbStatement, 1);
const char *location = (const char *)sqlite3_column_text(dbStatement, 2);
//Convert the returnedElement char to string
NSString *nameConverted = [[[NSString alloc] initWithUTF8String:name] autorelease];
NSString *locationConverted = [[[NSString alloc] initWithUTF8String:location] autorelease];
Course *course = [[Course alloc] initWithName:nameConverted _id:courseId location:locationConverted];
[tempArray addObject:course];
[course release];
course = nil;
}
self.courses = tempArray;
[tempArray release];
[self.tableView reloadData];
[super viewWillAppear:animated];
}
EDIT: Here's is the error log:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceWhiteColor _id]: unrecognized selector sent to instance 0x4d2e2a0'
Call stack at first throw:
(
0 CoreFoundation 0x010435a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01197313 objc_exception_throw + 44
2 CoreFoundation 0x010450bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00fb4966 ___forwarding___ + 966
4 CoreFoundation 0x00fb4522 _CF_forwarding_prep_0 + 50
5 BookApp 0x000079e8 -[CoursesCategoriesViewController viewWillAppear:] + 184
6 UIKit 0x0017c9be -[UINavigationController _startTransition:fromViewController:toViewController:] + 858
7 UIKit 0x0017732a -[UINavigationController _startDeferredTransitionIfNeeded] + 266
8 UIKit 0x0017e562 -[UINavigationController pushViewController:transition:forceImmediate:] + 932
9 UIKit 0x001771c4 -[UINavigationController pushViewController:animated:] + 62
10 BookApp 0x000056d6 -[CoursesViewController tableView:didSelectRowAtIndexPath:] + 374
11 UIKit 0x00135b68 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
12 UIKit 0x0012bb05 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
13 Foundation 0x0084579e __NSFireDelayedPerform + 441
14 CoreFoundation 0x010248c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
15 CoreFoundation 0x01025e74 __CFRunLoopDoTimer + 1220
16 CoreFoundation 0x00f822c9 __CFRunLoopRun + 1817
17 CoreFoundation 0x00f81840 CFRunLoopRunSpecific + 208
18 CoreFoundation 0x00f81761 CFRunLoopRunInMode + 97
19 GraphicsServices 0x012d81c4 GSEventRunModal + 217
20 GraphicsServices 0x012d8289 GSEventRun + 115
21 UIKit 0x000ccc93 UIApplicationMain + 1160
22 BookApp 0x00001ff9 main + 121
23 BookApp 0x00001f75 start + 53
)
terminate called after throwing an instance of 'NSException'
From your stack trace, the interesting parts are :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceWhiteColor _id]: unrecognized selector sent to instance 0x4d2e2a0'
and
5 BookApp 0x000079e8 -[CoursesCategoriesViewController viewWillAppear:] + 184
which corresponds to :
- (void)viewWillAppear:(BOOL)animated {
//...
NSString *sqlQuery =
[NSString stringWithFormat:
#"SELECT co.name, co.id, o.location FROM course as co JOIN categories as ca JOIN occasions as o WHERE co.catID = ca.id AND co.catID = %i AND o.courseID = co.id",
self.selectedCategory._id]; // << The culprit
//...
You get this because self.selectedCategory._id tries to send an _id message to self.selectedCategory and fails, self.selectedCategory not being the good type.
How could this be possible?
Since I guess you are sure that self.selectedCategory is the expected type...
Simply because self.selectedCategory has been released, and its address has been reused for another variable... of another type, in your trace a UIColor instance... Could be anything else.
Conclusion
Double check your retain/release of that self.selectedCategory property :)
Side note
+1 for the FMDB suggestion... A must!
Your code is leaking memory. You are not putting release after assigning temp array to self.courses. Also you are not releasing course object after adding it to temp array. For SQLite operations I suggest you to use FMDB. It will be very easier to manage then putting SQL queries in each view controller to fetch the data from database. Also It's a bad practice to follow this kind of pattern. Use FMDB for all your sqlite purpose. Create a seperate class for all the sqlite communication.