cocoa context and autorelease pools

  • Hi,
    I'm working on a Lua module for constructing Cocoa windows and am
    curious about a few points regarding when and where one can use Cocoa
    classes.  If I run the module from the command line and load the
    plugin and test script which attempts to build an NSWindow, I get the
    following errors at runtime:

    2007-12-17 00:16:09.893 lua[1465] *** _NSAutoreleaseNoPool(): Object
    0x3204e0 of class NSMutableParagraphStyle autoreleased with no pool in
    place - just leaking
    2007-12-17 00:16:09.893 lua[1465] *** _NSAutoreleaseNoPool(): Object
    0x31f570 of class NSCFDictionary autoreleased with no pool in place -
    just leaking
    2007-12-17 00:16:09.893 lua[1465] *** _NSAutoreleaseNoPool(): Object
    0x321f90 of class NSCFString autoreleased with no pool in place - just
    leaking
    2007-12-17 00:16:09.894 lua[1465] *** _NSAutoreleaseNoPool(): Object
    0x321ef0 of class NSException autoreleased with no pool in place -
    just leaking
    2007-12-17 00:16:09.894 lua[1465] *** Uncaught exception:
    <NSInternalInconsistencyException> Error (1002) creating CGSWindow

    Do I have to run this thing within an NSApplication?  Are there other
    contexts within which Cocoa can be used?  I'm not quite sure what's
    going on so any info or pointers to relevant docs is appreciated.

    thanks,
    wes
  • You always need an autoreoease pool. One per thread atleast.
    Because even if you release everything cocoa needs one internally

    Regards,
    Dominik

    Am Dec 17, 2007 um 9:24 AM schrieb Wesley Smith:

    > Hi,
    > I'm working on a Lua module for constructing Cocoa windows and am
    > curious about a few points regarding when and where one can use Cocoa
    > classes.  If I run the module from the command line and load the
    > plugin and test script which attempts to build an NSWindow, I get the
    > following errors at runtime:
    >
    > 2007-12-17 00:16:09.893 lua[1465] *** _NSAutoreleaseNoPool(): Object
    > 0x3204e0 of class NSMutableParagraphStyle autoreleased with no pool in
    > place - just leaking
    > 2007-12-17 00:16:09.893 lua[1465] *** _NSAutoreleaseNoPool(): Object
    > 0x31f570 of class NSCFDictionary autoreleased with no pool in place -
    > just leaking
    > 2007-12-17 00:16:09.893 lua[1465] *** _NSAutoreleaseNoPool(): Object
    > 0x321f90 of class NSCFString autoreleased with no pool in place - just
    > leaking
    > 2007-12-17 00:16:09.894 lua[1465] *** _NSAutoreleaseNoPool(): Object
    > 0x321ef0 of class NSException autoreleased with no pool in place -
    > just leaking
    > 2007-12-17 00:16:09.894 lua[1465] *** Uncaught exception:
    > <NSInternalInconsistencyException> Error (1002) creating CGSWindow
    >
    > Do I have to run this thing within an NSApplication?  Are there other
    > contexts within which Cocoa can be used?  I'm not quite sure what's
    > going on so any info or pointers to relevant docs is appreciated.
    >
    > thanks,
    > wes
  • So what is the procedure for detecting if one exists and creating one
    if none is detected?
    thanks,
    wes

    On Dec 17, 2007 1:12 AM, Dominik Pich <dominik...> wrote:
    > You always need an autoreoease pool. One per thread atleast.
    > Because even if you release everything cocoa needs one internally
    >
    > Regards,
    > Dominik
    >
    > Am Dec 17, 2007 um 9:24 AM schrieb Wesley Smith:
    >
    >
    >> Hi,
    >> I'm working on a Lua module for constructing Cocoa windows and am
    >> curious about a few points regarding when and where one can use Cocoa
    >> classes.  If I run the module from the command line and load the
    >> plugin and test script which attempts to build an NSWindow, I get the
    >> following errors at runtime:
    >>
    >> 2007-12-17 00:16:09.893 lua[1465] *** _NSAutoreleaseNoPool(): Object
    >> 0x3204e0 of class NSMutableParagraphStyle autoreleased with no pool in
    >> place - just leaking
    >> 2007-12-17 00:16:09.893 lua[1465] *** _NSAutoreleaseNoPool(): Object
    >> 0x31f570 of class NSCFDictionary autoreleased with no pool in place -
    >> just leaking
    >> 2007-12-17 00:16:09.893 lua[1465] *** _NSAutoreleaseNoPool(): Object
    >> 0x321f90 of class NSCFString autoreleased with no pool in place - just
    >> leaking
    >> 2007-12-17 00:16:09.894 lua[1465] *** _NSAutoreleaseNoPool(): Object
    >> 0x321ef0 of class NSException autoreleased with no pool in place -
    >> just leaking
    >> 2007-12-17 00:16:09.894 lua[1465] *** Uncaught exception:
    >> <NSInternalInconsistencyException> Error (1002) creating CGSWindow
    >>
    >> Do I have to run this thing within an NSApplication?  Are there other
    >> contexts within which Cocoa can be used?  I'm not quite sure what's
    >> going on so any info or pointers to relevant docs is appreciated.
    >>
    >> thanks,
    >> wes
    >
    >
  • don't bother detecting if one already exists; just create one unconditionally.

    On 12/17/07, Wesley Smith <wesley.hoke...> wrote:
    > So what is the procedure for detecting if one exists and creating one
    > if none is detected?
    > thanks,
    > wes
    >
    > On Dec 17, 2007 1:12 AM, Dominik Pich <dominik...> wrote:
    >> You always need an autoreoease pool. One per thread atleast.
    >> Because even if you release everything cocoa needs one internally
    >>
    >> Regards,
    >> Dominik
    >>
    >> Am Dec 17, 2007 um 9:24 AM schrieb Wesley Smith:
    >>
    >>
    >>> Hi,
    >>> I'm working on a Lua module for constructing Cocoa windows and am
    >>> curious about a few points regarding when and where one can use Cocoa
    >>> classes.  If I run the module from the command line and load the
    >>> plugin and test script which attempts to build an NSWindow, I get the
    >>> following errors at runtime:
    >>>
    >>> 2007-12-17 00:16:09.893 lua[1465] *** _NSAutoreleaseNoPool(): Object
    >>> 0x3204e0 of class NSMutableParagraphStyle autoreleased with no pool in
    >>> place - just leaking
    >>> 2007-12-17 00:16:09.893 lua[1465] *** _NSAutoreleaseNoPool(): Object
    >>> 0x31f570 of class NSCFDictionary autoreleased with no pool in place -
    >>> just leaking
    >>> 2007-12-17 00:16:09.893 lua[1465] *** _NSAutoreleaseNoPool(): Object
    >>> 0x321f90 of class NSCFString autoreleased with no pool in place - just
    >>> leaking
    >>> 2007-12-17 00:16:09.894 lua[1465] *** _NSAutoreleaseNoPool(): Object
    >>> 0x321ef0 of class NSException autoreleased with no pool in place -
    >>> just leaking
    >>> 2007-12-17 00:16:09.894 lua[1465] *** Uncaught exception:
    >>> <NSInternalInconsistencyException> Error (1002) creating CGSWindow
    >>>
    >>> Do I have to run this thing within an NSApplication?  Are there other
    >>> contexts within which Cocoa can be used?  I'm not quite sure what's
    >>> going on so any info or pointers to relevant docs is appreciated.
    >>>
    >>> thanks,
    >>> wes
    >>
    >>

    >

    --
    Clark S. Cox III
    <clarkcox3...>
  • Also, you have no way of creating an autorelease pool before main or before
    a library's entry point is called, so any case of a static variable being
    initialized with an Objective-C instance can give you those kinds of
    messages at startup. Three options:

    - Don't use statics for Objective-C instances.

    - Avoid convenience methods that autorelease, instead use alloc & initXXX
    methods.

    - Just live with a few messages in the console. Presumably objects assigned
    to statics are going to survive the entire process lifespan anyway, so the
    fact that if you were to not retain them they wouldn't be disposed would not
    be a problem. Of course, if this is not the case, and the objects should be
    released and the statics set to point to different objects, then you would
    have an actual leak.

    --
    Scott Ribe
    <scott_ribe...>
    http://www.killerbytes.com/
    (303) 722-0567 voice
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today