如何在 Objective-c 中自动释放
我没有使用自动释放。当我像这样使用代码时,我不知道如何释放 BSPTile
NSUInteger numbToday = [[dateFormatter stringFromDate:[NSDate date]] intValue];
BSPTileView *tile = [gridView.subviews objectAtIndex: 0];
tile.comparedValue = 0;
BSPTileView 是 UIView 类。怎么办?请。
I'm not using Autorelease. When I use like this code, I don't know How to release BSPTile
NSUInteger numbToday = [[dateFormatter stringFromDate:[NSDate date]] intValue];
BSPTileView *tile = [gridView.subviews objectAtIndex: 0];
tile.comparedValue = 0;
BSPTileView is UIView Class. How to do ? please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这种情况下,您不必这样做。
-objectAtIndex:
仅返回数组中该索引处的对象,而不更改其保留计数。In this case, you don't have to.
-objectAtIndex:
just returns the object at that index in the array, without changing its retain count.你不知道。您没有通过包含
new
、alloc
、retain
或copy
的方法调用接收此指针,因此您不负责释放(或自动释放)指针。如果您的应用程序的结构使得您必须在此处发布它,那么您在其他地方做错了。
You don't. You did not receive this pointer via a method call that contains
new
,alloc
,retain
, orcopy
, so you are not responsible for releasing (or autoreleasing) the pointer.If your application is structure such that you have to release it here, then you've done something wrong somewhere else.
如果您将 BSPTileView 插入视图层次结构中,则层次结构会为您管理对象。从子视图数组中获取对象不会更改保留计数。不转移任何责任。
If you have your BSPTileView inserted in a view hierarchy, the hierarchy takes care of managing the object for you. Taking the object from the subviews array does not change the retain count. No responsibility is transfered.