tags:

views:

61

answers:

2
-(void)setMedicineList:(NSString*)btnText:(NSString*)kana:(NSString*)skana

{

   if(mdcnList != nil)
   {
    [mdcnList 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.

A: 

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.

JosephH
How to retain a reference to mdcnList. I have already defined it as retain property in .h file.
Dhaval
That sounds correct. Your code here:[[MedicineList alloc]getMedicineList:btnText:kana:skana];does not call "init" - should it be [[[MedicineList alloc] init] get MedicineLine:...] ?You need to uncomment the release line, as that definitely should be there.
JosephH
A: 

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.

Macmade
Thanks. But above solution is not working. Warning: Potential leak of an object allocated on line 6921. Method returns an Objective-C object with a +1 retain count (owning reference)2. Object allocated on line 692 is no longer referenced after this point and has a retain count of +1 (object leaked)
Dhaval