2016-04-22 5 views
-1

私は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; 

     } 



    } 

私を導いてくださいeg.100関数の例を複数回呼ばれているいくつかのローカルのString variable.My機能がある私のapp.In各機能にいくつかの関数を使用していました。 Will above code increase the memory ?「はい」の場合、メモリを増やさないようにコードを書くための最適な解決策は何ですか?

+0

NSStringクラスの多くのNSStringを使用する必要があります。 – Vvk

+0

私は記憶が増えるとは思わない。値をnilに設定すると、ARCはメモリを解放する必要があります。 – dasdom

+0

なぜストレート文字列代入の代わりに 'stringWithFormat'を使用していますか? – Paulw11

答えて

1

あなたのコードはメモリが増加しないようです。次にARCは、使用後にローカル変数または参照を自動的にクリアします。だから、私のところでは記憶上の問題はない。これが助けてくれるといいでしょうか?

関連する問題