English 中文(简体)
缩略语
原标题:xcode project - memory leaks

我试图从我的项目中消除记忆泄露,但现在有2个局势中的一米 st。

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{

    if (currentElement) {
        [currentElement release];
        currentElement = nil;
    }
    currentElement = [elementName copy];

    if ([elementName isEqualToString:@"item"]) {

        item = [[NSMutableDictionary alloc] init]; //leak #1

        // DOING OTHER STUFF....
        //......................
    }

 }
/*****************************************************************************/
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{

    if ([elementName isEqualToString:@"item"]){

        [item setObject:currentTitle forKey:@"title"]; // leak #2
        [item setObject:currentLink forKey:@"link"];  //leak #3

        [bucket addObject:[item copy]]; // NSMutableArray *bucket
    }
}

关于泄漏第1号,我试图在分配记忆之前就释放该项目,但如果是失事的话。 (我指的是,在<代码>项目 = [[SMutableDictionary alloc] init];。 i 使用

if (item){
    [item release];
    item=nil;
}

在我的处理方式中,即还有<代码>[项目发布];。

For leaks #2 and #3 i have no idea what s happening. Note: The 2 methods are called by an xml parser while parsing an XML file, every time an element is read.That is, NSMutableDictionary * item is re-used for every element.

任何建议? 事先感谢你:

最佳回答

如你所知,一般规则是,对于灰色编码<>copy,retain,alloc,或new,也必须有<>release。 我认为,你可以打电话<条码>[项目副本]

如果做些什么,则尝试核对<代码>项目!= nil,而不是if(项目)

此外,考虑使用另外两个工具,即“Build”菜单和“NSZombie”的“Build And Analyze”,以发现你的其他记忆泄露。 此外,利用Leaks Instumeny去看图书馆造成泄漏的原因。 它可能是 Apple果。 如果是你的话,Leaks将帮助确定。 否则,这不是你的问题。

问题回答

暂无回答




相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签