开发者

The program created objective c++ is getting crash

开发者 https://www.devze.com 2023-04-10 11:44 出处:网络
I am developing a application to get list of installed software in Mac OS X 10.5 or above. The program is created using objective-c++ (c,c++, obj-c). Every time开发者_如何学JAVA I run the program, it

I am developing a application to get list of installed software in Mac OS X 10.5 or above. The program is created using objective-c++ (c,c++, obj-c). Every time开发者_如何学JAVA I run the program, it is crashing.

int main (int argc, const char * argv[])  
{
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];    
     //My part of coding
     [pool drain];  // This is the crash prone place
     return 0; 
}

Here I'm providing project setting details:

file extention: .mm

compiled as : objective c++

Objc GC : unsupported

libraries used : libxml2.2.dylib, Foundation Framework

target platfom: x86_x64

development: Mac OS X 10.6.8, Xcode 3.2.6

Application type: console application

I don't know any other option need to set to compile objective c++. Any help regarding this would be appreciated.

yes. I already set base sdk as 10.5

Here is the log trace:

The Debugger has exited with status 0. [Session started at 2011-10-03 22:29:25 +0530.] GNU gdb 6.3.50-20050815 (Apple version gdb-1515) (Sat Jan 15 08:33:48 UTC 2011) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys003 Loading program into debugger… Program loaded. run [Switching to process 2973] Running… Program received signal: “EXC_BAD_ACCESS”. sharedlibrary apply-load-rules all (gdb)

I have one more question. Is it valid to release the obj-c object in c++ class destructor? like this

myclass::myclasss() { myobjcinterface* myobjc = [[myobjcinterface alloc] init]; }

myclass::~myclass() { [myobjc release]; }


I have one more question. Is it valid to release the obj-c object in c++ class destructor? like this

Yes.

As for your EXC_BAD_ACCESS, if it's hapening on drain of an autorelease pool, it's almost certain that you have autoreleased something and released it, so the pool is trying to release a dangling pointer.

Try setting the environment variable NSZombieEnabled to YES and then running your program. It should give you diagnostics about over-releases.

0

精彩评论

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

关注公众号