"componentsSeparatedByString";内存泄漏 [英] "componentsSeparatedByString" Memory leak

查看:95
本文介绍了"componentsSeparatedByString";内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在现有的iPad应用程序中面临着一些奇怪的内存泄漏, 这是一个使仪器内存泄漏的功能

I am facing some strange memory leak in our existing iPad application, Here is a function which gives memory leak in instrument

-(NSString *)retriveInfo:(NSString*)fromstring:(NSString*)searchstring
{
    NSArray *arrRetrive = [fromstring componentsSeparatedByString:searchstring];
    if([arrRetrive count]!=0){
       if ([arrRetrive count]!=1){
            NSString *strDisplayOrder = [arrRetrive objectAtIndex:1];
            arrRetrive = [strDisplayOrder componentsSeparatedByString:@"<"];   //MEMORY LEAK
       }
     }

     return [arrRetrive objectAtIndex:0];
}

这里是输入参数

Param 1 : <displayorder>1</displayorder><filename>201103153_0100.pdf</filename><title>【1面】東日本巨大地震直撃、日経平均一時675円安[br]原発関連売られる、東電はS安</title><category>トップ・注目株</category><dirpath>/var/www/mssite/webapp/data/pdf/20110315</dirpath><TimeStamp>201103141700</TimeStamp><FirstPageImg>20110315top.png</FirstPageImg></pagedata>

Param 2: <displayorder>

基本上我想在开始和结束标记之间找到(解析)值. (我知道NSXMLParser类,但我先解释一下这是现有代码,如果我更改了代码,这会浪费很多时间)

Basically i want to found (parse) value between start and end tag. (I know NSXMLParser class but asper i explain this one is existing code and if i changed in code its too much time consuming)

有建议吗?

问候 Pankaj Gadhiya

With Regards Pankaj Gadhiya

推荐答案

您发布的代码看起来不像是在泄漏内存-您正在调用的所有方法都是autorelease类型的(即,没有<代码中的c0>,alloccopyretain).

The code you've posted doesn't look like it's leaking memory -- all the methods you're calling are of the autorelease type (i.e. there's no new, alloc, copy, or retain in the code).

可能是您拥有的代码调用了retrieveInfo,并且执行某些操作导致内存泄漏(例如,过度保留).泄漏工具将您指向componentsSeparatedByString,因为这是分配内存的地方,最终导致了内存泄漏.

It's probably the code you have that calls retrieveInfo and does something with the result that's leaking memory (e.g. overretaining it). The leaks tool is pointing you at the componentsSeparatedByString because that's where the memory was allocated which was eventually involved in a memory leak.

您能告诉我们如何调用retrieveInfo以及如何处理结果吗?

Can you show us how you call retrieveInfo and what you do with the result?

顺便说一句,如果嵌套的话有什么意义?

Btw, what's the point of this nested if?

if([arrRetrive count]!=0){
   if ([arrRetrive count]!=1)

这很浪费,您不妨编写此代码并获得相同的效果:

It's wasteful, you might as well write this and get the same effect:

if ([arrRetrive count] > 1)

这篇关于"componentsSeparatedByString";内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆