Can someone point me to a leak in this code?

后端 未结 1 1966
栀梦
栀梦 2021-01-16 00:29

DisplayMap.h

#import 
#import 


@interface DisplayMap : NSObject  {

    CLL         


        
1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-16 00:41

    Your subtitle property is declared with a copy attribute, which means you are responsible for releasing it. The following change to your dealloc method should do the trick:

    -(void)dealloc{
        [subtitle release];
        [title release];
        [super dealloc];
    }
    

    Edit: To elaborate: Cocoa's memory management rules state that you must release any memory that you alloc, retain or copy. In the case of synthesized properties, this means that you must include the appropriate release messages in your -dealloc method. See my own question on this topic for more details.

    In the sample code that you provided, the following line:

    ann.subtitle = [[xmlParameter objectAtIndex:i]objectAtIndex:1];
    

    Creates a copy of the indicated object. When you later call [ann release], that copied object will be leaked unless you explicitly release it.

    0 讨论(0)
提交回复
热议问题