strange memory things in ios
IBOutlet UITextView *readme;
[super viewDidLoad];
NSString *string = [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"README" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
readme.text = string;
This part of code makes EXC_BAD_ACCESS in UIApplicationMain when i change tab item to other. without this code everything working fine. Any ideas?
NSZombieEnabled = YES, but point is leave on same position while i press next step. IBOutlet is connected as reference outlet to readme. This is a stack.
0 libSystem.B.dylib calloc 1 libobjc.A.dylib NXHashInsert 2 libobjc.A.dylib
_NXHashRehashToCapacity 3 libobjc.A.dylib NXHashInsert 4 libobjc.A.dylib realizeClass(class_t*) 5 libobjc.A.dylib
_class_getNonMetaClass 6 libobjc.A.dylib _class_initialize 7 libobjc.A.dylib prepareForMethodLookup 8 libobjc.A.dylib lookUpMethod 9 libobjc.A.dylib
_class_lookupMethodAndLoadCache 10 libobjc.A.dylib objc_msgSend 11 UIKit -[UIWebDocumentView initSimpleHTMLDocumentWithStyle:editable:withFrame:withPreferences:] 12 UIKit -[UITextView commonInitWithWebDocumentView:isDecoding:] 13 UIKit -[UITextView initWithCoder:] 14 Foundation
_decodeObjectBinary 15 Foundation -[NSKeyedUnarchiver
_decodeArrayOfObjectsForKey:] 16 Foundation -[NSArray(NSArray) initWithCoder:] 17 Foundation
_decodeObjectBinary 18 Foundation _decodeObject 19 UIKit -[UIView initWithCoder:] 20 Foundation
_decodeObjectBinary 21 Foundation _decodeObject 22 UIKit -[UIRuntimeConnection initWithCoder:] 23 Foundation
_decodeObjectBinary 24 Foundation -[NSKeyedUnarchiver
_decodeArrayOfObjectsForKey:] 25 Foundation -[NSArray(NSArray) initWithCoder:] 26 Foundation
_decodeObjectBinary 27 Foundation _decodeObject 28 UIKit -[UINib instantiateWithOwner:options:] 29 UIKit
-[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] 30 UIKit -[UIViewController
_loadViewFromNibNamed:bundle:] 31 UIKit -[UIViewController loadView] 32 UIKit -[UIViewController view] 33 UIKit -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] 34 UIKit -[UITabBarController transitionFromViewController:toViewController:] 35 UIKit -[UITabBarController
_setSelectedViewController:] 36 UIKit -[UITabBarController
_tabBarItemClicked:] 37 UIKit -[UIApplication sendAction:to:from:forEvent:] 38 UIKit -[UITabBar
_sendAction:withEvent:] 39 UIKit -[UIApplication sendAction:to:from:forEvent:] 40 UIKit -[UIControl sendAction:to:forEvent:] 41 UIKit
-[UIControl(Internal) _sendActionsForEvents:withEvent:] 42 UIKit -[UIControl sendActionsForControlEvents:] 43 UIKit -[UIApplication sendAction:to:from:forEvent:] 44 UIKit -[UIControl sendAction:to:forEvent:] 45 UIKit
-[UIControl(Internal) _sendActionsForEvents:withEvent:] 46 UIKit -[UIControl touchesEnded:withEvent:] 47 UIKit
-[UIWindow _sendTouchesForEvent:] 48 UIKit -[UIApplication sendEvent:] 49 UIKit _U开发者_运维知识库IApplicationHandleEvent 50 GraphicsServices PurpleEventCallback 51 CoreFoundation
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ 52 CoreFoundation
__CFRunLoopDoSource1 53 CoreFoundation __CFRunLoopRun 54 CoreFoundation CFRunLoopRunSpecific 55 CoreFoundation CFRunLoopRunInMode 56 GraphicsServices GSEventRunModal 57 GraphicsServices GSEventRun 58 UIKit UIApplicationMain 59 snow iphone main /Users/mac/Documents/Programming/Projects/snow
- head/snow iphone/main.m:13 60 snow iphone start
SOLUTION
UIImage *imageForEvents = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"events" ofType:@"png"]];
UITabBarItem *eventsBar = [[UITabBarItem alloc] initWithTitle:@"Events" image:imageForEvents tag:0];
events.tabBarItem = eventsBar;
[eventsBar release];
this peace of code was create in table view controller area. after i was change it to appdelegate, error was go out. strange that debug don't show appropriate line of code.
Set NSZombieEnabled to check which object is responsible for EXC_BAD_ACCESS.
Are you sure readme IBOutlet is exactly connected in Interface Builder?
NSLog(@"className of readme is \"%@\".", [readme className]);
BTW, UITextView text property has copy attribute, autoreleased string would be nice.
NSString *string = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"README" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
The code you have posted should not cause EXC_BAD_ACCESS. Since EXC_BAD_ACCESS is what happens when you try to send a message to a class that has deallocated, I would look in your app for where you either release something and do not set the pointer to nil or if you should be retaining something and are not doing so.
精彩评论