Value stored during its initialization is never read

谁都会走 提交于 2019-12-06 01:55:40
Game *newGame = [[Game alloc] init];//error 1

You create a new instance and you own it since you’ve used +alloc.

newGame = [gamesArray objectAtIndex:gameNumber];

You obtain another instance from gamesArray and assign it to the same variable that was used in the previous line. This means that you’ve lost the reference to the previous object and, since you own the previous object, you’re responsible for releasing it. You don’t, so you’re leaking that object.

[newGame release];//error 2

At this point newGame points to the instance via from gamesArray. You do not own it since you haven’t obtained it via NARC, hence you should not release it.

NARC: a method whose name contains new, alloc, copy, or is retain.

Bottom line: you’re leaking the object that you’ve created via +alloc and you’re trying to release an object that you do not own.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!