1

I have a "mysterious" retain in my app and I was able to reproduce it in simplification. I have a view hierarchy as follows:

  • Base view (UIView) :
    • Main view (UIView) :
      • Button1 (UIRectButton)
    • Kind-of side menu (UIView) :
      • Button2 (UIRectButton)

When I press button1 new view of class MyView (let's name it view with image) is created and added as subview to Main view. MyView is direct subclass of UIView and only custom thing it does is tracking retains, releases and autoreleases (calling super, ofcourse). So view with image is retained and it's OK.

After that I press button2. Here is where "mystery" occurs.

When I touch button, before any callback I can think of, including touchesBegan, is called, view with image is retained once more. Call stack shows it is something from system hit testing. And no release follows. Nor autorelease.

Tested on iOS 5 simulator and device.

Looks like I overlooking something. What am I doing wrong?

Edit:

Found that that odd retain would not spoil anything, and will be released by iOS when appropriate, for example when setting a superview (new one or the same) to view. But I still wonder, for what reason does second retain occur?

0 Answers0