2010-03-02 18 views
5

से EXC_BAD_ACCESS को डिबग करना मेरे कंसोल में EXC_BAD_ACCESS संदेश था। मैंने पर्यावरण चर के बारे में पढ़ा है NSZombieEnabled और MallocStackLoggingNoCompact this site पर। मैंने अपने पर्यावरण चर बनाए: NSZombieEnabled = YES और MallocStackLoggingNoCompact = 1। संदेश deallocated उदाहरण के लिए भेजा 0x58448e0एनएसएसटींग

: - 13:: 46.924 CruzNomad [7952 207] [CFString stringByAddingPercentEscapesUsingEncoding:] *** कंसोल में, मैं

2010-03-01 19 देखा

तब (gdb) प्रॉम्प्ट पर, मैंने किया था जानकारी malloc-इतिहास 0x58448e0 है, जो मुझे दिया:

Alloc: Block address: 0x058448e0 length: 64 
Stack - pthread: 0xa0b33500 number of frames: 25 
    0: 0x98e089bc in malloc_zone_malloc 
    1: 0x21516aa in _CFRuntimeCreateInstance 
    2: 0x2152bf8 in __CFStringCreateImmutableFunnel3 
    3: 0x21567d9 in CFStringCreateCopy 
    4: 0x21742fc in _CFStringCreateWithFormatAndArgumentsAux 
    5: 0xdb546 in -[NSPlaceholderString initWithFormat:locale:arguments:] 
    6: 0xdb4d8 in +[NSString stringWithFormat:] 
    7: 0x23aa3 in -[BuisnessCardViewController viewDidLoad] at /Users/.../Classes/BuisnessCardViewController.m:85 
    8: 0x3d6796 in -[UIViewController view] 
    9: 0x347b4 in -[gm_menuViewController btn5_Pressed:] at /Users/.../Classes/menuViewController.m:535 
    10: 0x357459 in -[UIApplication sendAction:to:from:forEvent:] 
    11: 0x3baba2 in -[UIControl sendAction:to:forEvent:] 
    12: 0x3bcdc3 in -[UIControl(Internal) _sendActionsForEvents:withEvent:] 
    13: 0x3bbb0f in -[UIControl touchesEnded:withEvent:] 
    14: 0x370e33 in -[UIWindow _sendTouchesForEvent:] 
    15: 0x35a81c in -[UIApplication sendEvent:] 
    16: 0x3610b5 in _UIApplicationHandleEvent 
    17: 0x2984ed1 in PurpleEventCallback 
    18: 0x2197b80 in CFRunLoopRunSpecific 
    19: 0x2196c48 in CFRunLoopRunInMode 
    20: 0x298378d in GSEventRunModal 
    21: 0x2983852 in GSEventRun 
    22: 0x362003 in UIApplicationMain 
    23: 0x2c8c in main at /Users/.../source/main.m:14 
    24: 0x2bfa in start 

लाइन 7 का कहना है कि समस्या BuisnessCardViewController.m की लाइन 85 में थी। यही कारण है कि लाइन यहाँ है:

fullAddress = [NSString stringWithFormat:@"%@ %@", fullAddress, myString]; 

मैं fullAddress और myString की सामग्री को जोड़कर रहा हूँ और fullAddress में इसे वापस भंडारण।

यदि मैं इसे सही तरीके से व्याख्या कर रहा हूं, तो ऐसा लगता है कि इस पंक्ति के बाद, fullAddress को हटा दिया गया है। जब मैं एक ब्रेकपॉइंट ड्रॉप करता हूं और चर पर होवर करता हूं, तो इसका मान "दायरे से बाहर" कहता है।

fullAddress इस विधि में बाद में काम करता है। मैं इसे उसी विधि के लाइन 164 में रिवर्स जियोकोडिंग के लिए Google को भेजने के लिए भेजता हूं।

NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", [fullAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

यहां तक ​​कि, यह "दायरे से बाहर" कहता है। मैं फंस गया हूँ ... कोई सलाह ??

धन्यवाद!

थॉमस

+0

क्या आप थोड़ा और संदर्भ पोस्ट कर सकते हैं? यदि यह कहता है कि चर का दायरा खत्म हो गया है, तो क्या हम पूरे दायरे को देख सकते हैं? –

+0

क्या आप कहीं भी 'fullAddress' या' myString' का उपयोग कर रहे हैं? – FelixLam

+0

इसके अलावा, अगर यह एक दुर्घटना हो, तो आपने बिजनेस के रूप में व्यवसाय को गलत बताया है। – dreamlax

उत्तर

3

ज्यादातर मामलों में ऐसा होता है जब आप एक विशेषता है जो वस्तु है बनाए रखने नहीं है और में इसे करने के लिए देर से संदेश भेजने देर से अन्य तरीकों।

तो, जहां कुछ तार कोशिश प्रारंभ कर रहे हैं:

[fullAddress retain]; 

या

[myString retain]; 

निर्भर करता है जो एक अन्य विधि में आरंभ नहीं हो जाता।

+0

अगर प्रतिक्रिया पूरी तरह से स्पष्ट नहीं है, तो कृपया मेरी भाषा के लिए क्षमा करें और टिप्पणी करें। – mxg

1

आप प्रारूप के साथ स्ट्रिंग जोड़कर की कोशिश की है?

fullAddress = [NSString stringWithFormat:@"%@ %@", fullAddress, myString]; 

साथ:

- (NSString *)stringByAppendingFormat:(NSString *)format ... 

इस तरह:

[fullAddress stringByAppendingFormat:@" %@", myString]; 
+0

उत्तर के लिए धन्यवाद, दोस्तों। और नहीं, मुझे नहीं पता था कि व्यापार गलत लिखा गया था। @dreamlax - मैंने उस वर्ग को लिखा नहीं है (शुक्रिया lol): -) ... मैं सिर्फ विशिष्ट विशेषताओं पर काम कर रहा हूं। हालांकि इसे इंगित करने के लिए धन्यवाद! मैंने अपनी समस्या का पता लगाया। चूंकि stringWithFormat एक ऑटोरेलेज्ड ऑब्जेक्ट देता है, इसलिए मैंने विधि में पहली बार इसे इस्तेमाल करने के बाद इसे ठीक से बनाए रखा। [fullAddress बरकरार रखें]; चाल चल रही थी (जैसा कि अब मैं एमएक्सजी ने सुझाव दिया है)। एक बार फिर, सभी को धन्यवाद! -थॉमस – Thomas