2011-07-18 128 views
0

如下intialised NSMutableString幫助:應用程序崩潰時,我嘗試着發佈的NSMutableString請在此

-(NSString*)filterIt:(NSString*)source 
{ 
    temp1= [[NSString alloc] initWithString:[source stringByReplacingOccurrencesOfString:@"rlm;" withString:@""]]; 
    //NSString *m_temp; 
    temp1 = [temp1 stringByReplacingOccurrencesOfString:@"&" withString:@""]; 
    temp1 = [temp1 stringByReplacingOccurrencesOfString:@"#x" withString:@"&#x"]; 
    NSRange range = [temp1 rangeOfString:@"&#x"]; 
    NSRange range1 = NSMakeRange(range.location, 8); 
    if (range1.location != NSNotFound) { 
     NSString* temp2 = [temp1 stringByReplacingCharactersInRange:range1 withString:@""]; 
     //[temp1 setString:temp2]; 
     temp1 = temp2; 
     range = [temp1 rangeOfString:@"&#x"]; 
     while (range.location < [temp1 length]) { 
      range1 = NSMakeRange(range.location, 8); 
      temp2 = [temp1 stringByReplacingCharactersInRange:range1 withString:@""]; 
      //[temp1 setString:temp2]; 
      temp1 = temp2; 
      range = [temp1 rangeOfString:@"&#x"]; 
     } 
    } 
    //m_temp = [temp1 mutableCopy]; 
// [temp1 release]; 
    return temp1; 
} 

,如果我嘗試釋放此字符串dealloc方法,並嘗試運行應用程序我的應用程序崩潰。

,請給我一些建議,我怎麼可以釋放這個temp1中提前

感謝

+0

請發佈錯誤信息。 – PengOne

+0

你在哪裏試圖釋放它?在相同的功能?或外面的功能? – Maulik

+0

你是否在某處重寫'temp1'?總之,正如你所看到的評論:你需要提供*方式*更多的信息和上下文。 – DarkDust

回答

1

你可以返回你的可變的字符串作爲自動釋放

OR

參考this...

+0

感謝您的回覆maulik ....如果我嘗試釋放我的應用程序是崩潰 –

+0

從dealloc方法中刪除代碼..然後嘗試 – Maulik

+0

yes..tried像那樣只...不工作...即時通訊嘗試發佈我的代碼,但不接受在此文本框 –

0

我假設你正在打這個電話在一個方法裏面。根據您提供的代碼,確保代碼片段居然是:

temp1= [[NSMutableString alloc] initWithString:[source stringByReplacingOccurrencesOfString:@"rlm;" withString:@""]];

我假設你正在呼籲stringByReplacingOcurrenceOfString:withString:消息人士透露。

說了這樣的話,你聲稱程序在達到'dealloc'時會崩潰。這就意味着temp1在你的代碼中被聲明爲一個實例變量......如果是這樣的話,正確的代碼應該是假設temp1中與保留屬性集聲明的屬性):

self.temp1 = [[NSMutableString alloc] initWithString:[source stringByReplacingOccurrencesOfString:@"rlm;" withString:@""]];

如果temp1中不是一個實例變量,也不是財產,你可能想表明temp1中是一個的NSMutableString的方法內部和返回自動釋放的對象。

+0

您剛添加了更多的代碼。試圖更好地展示它。這是不可讀的。 –

+0

看來temp1是一個實例變量。它是否也具有設置了保留屬性的屬性? –

相關問題