减少iOS中NSString的内存?

减少iOS中NSString的内存?,ios,objective-c,iphone,Ios,Objective C,Iphone,我在我的应用程序中使用了几个函数。每个函数中都有一些局部字符串变量。我的函数被多次调用,例如100函数示例 -(void)getData { if(result==1) { NSString *componentid=[NSString stringWithFormat:@"%@",subcomponent.componentid]; NSString *componentsubc

我在我的应用程序中使用了几个函数。每个函数中都有一些局部字符串变量。我的函数被多次调用,例如100函数示例

 -(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;

        } 



    } 

请指导我。
上面的代码会增加内存吗?
如果是,那么编写代码的最佳解决方案是什么,这样内存就不会增加。

否您的代码似乎不会增加内存。第二件事是使用后自动清除局部变量或引用。所以,据我所说,没有记忆问题的可能性。希望这会有所帮助:)

您必须使用NSobject类而不是许多NSString。我认为内存不会增加。将值设置为nil时,ARC应释放内存。为什么要使用
stringWithFormat
而不是直接字符串赋值?