开发者

Is there a leak in the Scroll View Suite sample code by Apple?

开发者 https://www.devze.com 2023-02-18 02:38 出处:网络
I need help with the c开发者_运维知识库ode from Apple\'s ScrollViewSuite; specifically I\'m looking at the ThumbImageView class, which doesn\'t have a dealloc method defined.I see in the .h that the p

I need help with the c开发者_运维知识库ode from Apple's ScrollViewSuite; specifically I'm looking at the ThumbImageView class, which doesn't have a dealloc method defined. I see in the .h that the property for imageName uses retain.

(I wasn't sure if I was allowed to post any code since it's Apple's, so please let me know if I can/should.)

  1. Anyway, I thought if we use "retain" that we are responsible for releasing the object reference.

  2. The method CreateThumbScrollViewIfNecessary (from the RootViewController implementation file) has a for loop which allocs ThumbImageViews, sets the delegate, and then after adding the thumbview as a subview the a scrollview, proceeds to release the thumbview. If these objects are actually being released, how does the delegate do its job notifying when an image has been tapped, scrolled, etc.

Sorry I'm just so confused. Any help would be greatly appreciated.


The code leaks. Unfortunately, Apple’s sample code usually leaves a lot to be desired, the design often sucks and there are leaks and glitches. It’s best to take it only as an annotated API reference that shows how various parts of the API fit together, nothing more.


  1. You are responsible for clearing the object reference. As far as I can tell, that code of Apple's would leak if that property were ever assigned a value.
  2. Any view retains its subviews. After each view has been added to the scrollview, the class that creates it has no more use for it so it releases its reference. The object won't actually be deallocated until the scrollview also releases its reference, so the views remain "live" and able to signal their delegates until that happens.
0

精彩评论

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