开发者

iPhone: Newbie memory management question

I am just getting started with cocoa. So please excuse the silly question, but I can't quite wrap my head around some aspects of memory management yet.

In the interface of my class I am declaring an object as CEMyObjectclass *myObject;. I do not alloc or init the obect in the classe's init menthod. But I do have a method that calls myObject = [[CEMyObjectclass alloc] initWithImage:someImage];. Will that eventually run out of memory or does myO开发者_如何学JAVAbject just get overwritten by a new instance every time that method is called?

Thanks!


You should eventually run out.

Remember that myObject is just a pointer to a block of memory. The pointer myObject will be pointing to the newly allocated object, and you'll have no reference to the old one. Therefore, you won't be able to release its memory (but the object will still be around).

In general, if you alloc something (or retain it), you are responsible for matching this message with a release somewhere later.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜