-1

While profiling my app with Instruments, I found a leak with an array that I allocated. To my knowledge I was doing this correctly, but it looks like something is wrong.

Let's say I have three classes, class M, A and B.

  • Subclass B has a unique NSArray property that is not a part of it's super class A.
  • M allocates and instance of subclass B.
  • In class M, the instance of subclass B is accessed, and the NSArray property is accessed from that class and allocated.
  • In subclass B, dealloc is overridden and has a release for the NSArray, and super dealloc is under it.
  • When I release class M, I get a leak for the NSArray object.

My understanding was that I was able to allocate the NSArray object from class M, for example:

tempClassB.myNSArray = [[NSArray alloc] initWithArray:finalArray];

And that I can override dealloc in subclass B to release it's own object that does not exist in it's super class, A. I than can call super dealloc to call dealloc in class A:

- (void) dealloc{

    [myNSArray release];

    [super dealloc];

}
Chewie The Chorkie
  • 3,401
  • 4
  • 37
  • 77

1 Answers1

0

The problem I'm having is allocating class B in class M will make class M responsible for releasing it. I should allocate the object in class B and release like I am, or put a release in class M's dealloc for the object.

Chewie The Chorkie
  • 3,401
  • 4
  • 37
  • 77