Released object crashes app
Posted
by John Smith
on Stack Overflow
See other posts from Stack Overflow
or by John Smith
Published on 2010-04-16T17:19:00Z
Indexed on
2010/04/16
17:23 UTC
Read the original article
Hit count: 182
I am using objective-C++ (+Boost) for iPhone development.
I am in a rather tight loop and need to allocate and release a certain object.
The code is something like this.
for (int i=0;i<100;i++)
{
opt = [[FObj alloc] init];
//do stuff with opt
[opt release];
}
The FObj object is something like
@interface FObj
MyCPPObj * cppobj;
@end
In the implementation of FObj there is a dealloc method:
-(void) dealloc
{
delete cppobj; //previously allocated with 'new'
[super dealloc];
}
I am afraid that if i don't release then the 'MyCPPObj's will just pile up. But releasing makes the app crash after the first loop. What am I doing wrong?
Or perhaps should I make cppobj and boost::shared_ptr?
(do boost shared pointers automatically release their objects when an objective-C++ object is deleted?)
© Stack Overflow or respective owner