thanks a lot for the answer, Jens

but that how my problem began :-)
from creating my own NSAutoreleasePool

here is my code

        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *nsFontName = [NSString stringWithCString:fontName encoding:NSMacOSRomanStringEncoding]; NSString *textString = [NSString stringWithCString:"Hello From Cocoa" encoding:NSMacOSRomanStringEncoding];
        NSPoint p = NSMakePoint(qdX, qdY);
NSGraphicsContext *oldContext = [NSGraphicsContext currentContext]; NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithGraphicsPort:cgContext flipped:TRUE];
        [NSGraphicsContext setCurrentContext : context];
NSColor *cocoaColor = [NSColor colorWithCalibratedRed:r green:g blue:b alpha:alpha];
        NSFont *font = [NSFont fontWithName:nsFontName size:fontSize];
NSMutableDictionary *stringAttributes = [NSMutableDictionary dictionaryWithCapacity:4];
        [stringAttributes setObject:font forKey:NSFontAttributeName];
[stringAttributes setObject:cocoaColor forKey:NSForegroundColorAttributeName];

        [textString drawAtPoint:p withAttributes:stringAttributes];

        [NSGraphicsContext setCurrentContext : oldContext];

        [stringAttributes release];
        [font release];
        [cocoaColor release];
        [context release];
        [textString release];
        [nsFontName release];
        [pool release];

and application crashes with the stack

(gdb) bt 10
#0  0x91a156e8 in objc_msgSend ()
#1  0x94108fdf in NSPopAutoreleasePool ()
#2 0x10a033d6 in Cocoa_DrawText (color=0xbfffebf6, fontName=0x10a38604 "Times New Roman Bold", fontSize=24, qdX=38, qdY=50, text=0x10a385f8 "Hello World", alpha=1) at ....../models/ AcDc/../../../models/AcDc/src/acdc/acdc.cpp:1691 #3 0x10a034b2 in CAcdc::DoUpdate (this=0xe661760) at ....../models/ AcDc/../../../models/AcDc/src/acdc/acdc.cpp:1724
#4  0x10a09f22 in CAcdc::ReadData (this=0xe661760) at ....../



that's how I started to look at it
also I'm not sure I have to release all of those objects, like cocoaColor, font e.t.c.

I became suspicious when
NSString *nsFontName = [NSString stringWithCString:fontName encoding:NSMacOSRomanStringEncoding];
didn't complain about absence of the pool (if I didn't create my own)


Note: our main application isn't linked against Cocoa framework at all
it linked against CoreFoundation, QuickTime, Carbon, CoreServices, ApplicationServices frameworks
our application uses 10.4 SDK
and as far as I can see none of those frameworks (in 10.4u.sdk) don't use Foundation or AppKit

however our bundle linked against Cocoa framework

thanks










On Apr 3, 2008, at 8:47 PM, Jens Alfke wrote:


On 3 Apr '08, at 5:07 PM, Robert Claeson wrote:

The default autorelease pool is created in the <project name>.m file of a newly created project. If you have messed around too much with that file, you might have deleted it.

There's not a "default" autorelease pool. They form a stack, and get pushed and popped dynamically.

It's true that the very outermost pool on the main thread is created in main(); but hopefully nothing your app is doing dynamically will end up using that pool, because objects autoreleased into it will hang around until the app quits.

But usually when your app code is running, it's responding to events or timers or other actions under the control of the runloop, so the topmost autorelease pool is a temporary one created by the runloop for the duration of that call (and cleaned up as soon as your code returns.)

To answer the original question: I don't think you can tell whether there's an autorelease pool active. But it doesn't matter: if you're doing anything that could autorelease objects, and there might not be a pool already, create your own by calling [NSAutoreleasePool new] beforehand and [pool drain] afterwards.

—Jens

Dmitry Markman

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to