Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / July 2005



Tip: Looking for answers? Try searching our database.

NSAutoreleasePool in carbon application

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Konstantin Schauwecker - 30 Jul 2005 11:59 GMT
Hi everybody

I am using the carbon library in my application to display a native
file choose dialog. Works fine so far, but when the dialog displays it
prints a lot of warnings to the console like:

_NSAutoreleaseNoPool(): Object 0x136b320 of class NSImage autoreleased
with no pool in place - just leaking

Searching around the web, I found out that I need to create a
NSAutoreleasePool object, but I could just find the Objective C
bindings (I'm writing in c++). Even worse, on several apple documents
they claimed, that if you want to combine Objective C and C functions
you must add an NSAutoreleasePool to your Objective C functions (that
sounds to me like there isn't a possibility to create a
NSAutoreleasePool in C).

Does anybody has an idea on how to get rid of this warning?

Here is my code:

string OpenDialog::runCarbon()
{
#ifdef HAVE_CARBON
    NavDialogCreationOptions dlgOptions;
    NavGetDefaultDialogCreationOptions(&dlgOptions);
    dlgOptions.location.v=dlgOptions.location.h=-1;
    dlgOptions.windowTitle=CFStringCreateWithCString(0, title.c_str(),
        CFStringGetSystemEncoding());
    dlgOptions.modality=kWindowModalityAppModal;

    NavDialogRef dialogRef;
    NavCreateChooseFileDialog(&dlgOptions, 0, 0, 0, 0, 0, &dialogRef);
    NavDialogRun(dialogRef);

    NavUserAction result = NavDialogGetUserAction(dialogRef);
    if (result == kNavUserActionChoose)
    {
        NavReplyRecord reply;
        memset(&reply, '\0', sizeof(reply));
        NavDialogGetReply(dialogRef, &reply);

        if (reply.validRecord)
        {
            AEKeyword keyword;
            FSRef ref;

            AEGetNthPtr(&reply.selection, 1, typeFSRef, &keyword,
                NULL, &ref, sizeof(ref), NULL);
            CFURLRef url=CFURLCreateFromFSRef(NULL, &ref);
            CFStringRef urlString=CFURLCopyFileSystemPath(url,
                kCFURLPOSIXPathStyle);
            CFRelease(url);
            return string(CFStringGetCStringPtr(urlString,
                kCFStringEncodingMacRoman));
        }
        NavDisposeReply(&reply);
    }
    NavDialogDispose(dialogRef);
#endif
    return "";
}
Ulrich Hobelmann - 30 Jul 2005 12:41 GMT
> Hi everybody
>
[quoted text clipped - 14 lines]
>
> Does anybody has an idea on how to get rid of this warning?

The warning has a reason, so solve the problem: create an
autorelease pool.  You could create a .m file with a function that
creates the pool, and call that function (void) from the C file,
or you could compile the C file with an objc flag (see the
man-page) and just create a pool right there.

After the dialog stuff you should then destroy the pool to free
memory.

Signature

XML is a prime example of retarded innovation.
    -- Erik Meijer and Peter Drayton, Microsoft Corporation

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.