views:

258

answers:

0

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?)