2016-04-22 24 views
-1

我已經使用一些功能在我app.In每個功能也有一些地方的字符串variable.My函數被調用多次eg.100功能例如在iOS中減少NSString的內存?

-(void)getData 
    { 
     if(result==1) 
     { 
      NSString *componentid=[NSString stringWithFormat:@"%@",subcomponent.componentid]; 
         NSString *componentsubclientid=[NSString stringWithFormat:@"%@",subcomponent.componentsubclientid]; 
         NSString *componentClientid=[NSString stringWithFormat:@"%@",subcomponent.componentClientid]; 
         NSString *componentEntityid=[NSString stringWithFormat:@"%@",subcomponent.componentEntityid]; 
         NSString *componentWorkorderid=[NSString stringWithFormat:@"%@",subcomponent.componentWorkorderid]; 
         NSString *componentStatus=[NSString stringWithFormat:@"%ld",(long)subcomponent.componentStatus]; 
         NSString *notes=[NSString stringWithFormat:@"%@",subcomponent.componentNotes]; 
         NSString *componentAllImages=[NSString stringWithFormat:@"%@",subcomponent.componentAllImages]; 
         NSString *componentAllImagesTime=[NSString stringWithFormat:@"%@",subcomponent.componentAllImagesTime]; 

//after some code 

componentinspectionid=nil; 
        inspectorid=nil; 
        componentid=nil; 
        componentsubclientid=nil; 
        componentClientid=nil; 
        componentEntityid=nil; 
        componentWorkorderid=nil; 
        componentStatus=nil; 
        notes=nil; 
        componentAllImages=nil; 
        componentAllImagesTime=nil; 

     } 



    } 

請指引我。 Will above code increase the memory ?如果是,那麼編寫代碼的最佳解決方案是讓內存不會增加。

+0

你必須使用許多NSString的NSobject類insted。 – Vvk

+0

我不認爲內存會增加。當您將值設置爲零時,ARC應釋放內存。 – dasdom

+0

爲什麼你使用'stringWithFormat'而不是一個直接的字符串賦值? – Paulw11

回答

1

沒有你的代碼似乎不會增加內存。第二件事ARC使用後自動清除局部變量或引用。所以,根據我的說法,沒有記憶問題的可能性。希望這會有所幫助:)