开发者

iPhone: Newbie memory management question

开发者 https://www.devze.com 2022-12-25 22:57 出处:网络
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.

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

精彩评论

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