2012-04-23 9 views
6

मैं कॉन्स्ट char * को NSString * में परिवर्तित करने की कोशिश कर रहा हूं और फिर इसे वापस परिवर्तित कर रहा हूं। यह काम करता है, लेकिन मैं मिलता है:कॉन्स char * से NSString में कनवर्ट करें * और वापस कनवर्ट करें - _NSAutoreleaseNoPool()

__NSAutoreleaseNoPool(): Object 0x100550a40 of class NSCFArray autoreleased with no pool in place - just leaking 
__NSAutoreleaseNoPool(): Object 0x100551730 of class NSCFString autoreleased with no pool in place - just leaking 
__NSAutoreleaseNoPool(): Object 0x100551f10 of class NSCFData autoreleased with no pool in place - just leaking 

कोड है:

const char* convert = "hello remove this: *"; 

NSString *input = [[NSString alloc] initWithUTF8String:convert];// convert 

//remove * FROM THE STRING   
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"*"]; 

// REPLACE * WITH NOTHING     
input = [[input componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""]; 

// CONVERT BACK   
const char *converted_back = [input UTF8String]; 

मैं भटक गया हूँ, मेरी मदद कृपया बाहर।

+0

अपना पूरा कोड दिखाएं, मुझे लगता है कि मुझे पता है कि समस्या क्या है लेकिन मुझे पहले अपना पूरा कोड जांचना होगा। –

उत्तर

15

यदि आप इसे पृष्ठभूमि थ्रेड में कर रहे हैं, तो एक NSAutoReleasePool जोड़ें।

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 
const char* convert = "hello remove this: *"; 
NSString *input = [[[NSString alloc] initWithUTF8String:convert] autorelease];// convert 
//remove * FROM THE STRING   
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"*"]; 
// REPLACE * WITH NOTHING     
input = [[input componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""]; 
// CONVERT BACK   
const char *converted_back = [input UTF8String]; 
[pool drain]; 

इसके अलावा, आप input रिलीज के बाद आप इसे पूरा कर चुके हैं, या यह autoreleased बनाने की जरूरत है।

+0

मैं इसे हेडरफ़ाइल में कर रहा हूं, फिर मैं इसे एनएसपीप्लिकेशन डिलीगेट सॉस के अंदर शामिल/आयात करता हूं, क्या आप मुझे एक उदाहरण दिखा सकते हैं, क्योंकि मैं इस पर नया हूं .. – user1341993

+0

मुझे प्रोग्राम प्राप्त संकेत प्राप्त हो रहा है: "EXC_BAD_ACCESS"। – user1341993

+0

@ user1341993 - देखें – MByD

संबंधित मुद्दे