开发者

Potential leak of an object allocated on line 576

开发者 https://www.devze.com 2023-01-06 10:21 出处:网络
-(void)setMedicineList:(NSString*)btnText:(NSString*)kana:(NSString*)skana { if(mdcnList != nil) { [md开发者_JAVA技巧cnList release];
-(void)setMedicineList:(NSString*)btnText:(NSString*)kana:(NSString*)skana

{

   if(mdcnList != nil)
   {
    [md开发者_JAVA技巧cnList release];
   }

   mdcnList = [[MedicineList alloc]getMedicineList:btnText:kana:skana]; // Memeory leak

   [medListView setMdcnList:mdcnList];


   [btnText release];
   //[mdcnList release];  // Not work
}

How to release mdcnList to avoid "Potential leak of an object allocated on line 576" warning ? "getMedicineList" is another function. MedicineList is Class.


I'm not sure what your "// Not work" means - you mean the [mdcnList release] causes a problem?

Assuming so, that line should be uncommented. The problem may well be [medListView setMdcnList:] is not retaining a reference to mdcnList, when it should be.


I assume mdcnList is a property. If it's defined as retain, you should use the accessor, instead of releasing the iVar, and setting it manually...

Replace

if(mdcnList != nil) { [mdcnList release]; }
mdcnList = [[MedicineList alloc]getMedicineList:btnText:kana:skana];

By something like:

self.mdcnList = [ [ [ MedicineList alloc ] getMedicineList: btnText: kana: skana ] autorelease ];

As you can see, we are auto-releasing the object, as it will be automatically retained by the accessor.

0

精彩评论

暂无评论...
验证码 换一张
取 消