iOS 在命中测试中保留视图树?
我的应用程序中有一个“神秘”的保留,我能够以简化的方式重现它。 我的视图层次结构如下:
- 基本视图 (UIView) :
- 主视图(UIView):
- 按钮1(UIRectButton)
- 某种侧面菜单(UIView):
- 按钮2(UIRectButton)
- 主视图(UIView):
当我按下 button1 时,会创建并添加类 MyView 的新视图(让我们将其命名为带图像的视图)作为主视图的子视图。 MyView 是UIView 的直接子类,它所做的唯一自定义事情是跟踪保留、释放和自动释放(当然,调用super)。所以带图像的视图被保留,就可以了。
之后我按button2。这就是“谜”发生的地方。
当我触摸按钮时,在调用我能想到的任何回调(包括 touchesBegan)之前,带图像的视图将再次保留。调用堆栈显示它来自系统命中测试。并且没有随后发布。也不自动释放。
在 iOS 5 模拟器和设备上进行了测试。
看来我忽略了一些东西。我做错了什么?
编辑:
发现奇怪的保留不会破坏任何东西,并且会在适当的时候由iOS释放,例如当设置一个超级视图(新的或相同的)来查看时。但我还是想知道,为什么会发生第二次retain呢?
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)
- Main view (UIView) :
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论