• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Mixing CPP and Obj-C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mixing CPP and Obj-C


  • Subject: Re: Mixing CPP and Obj-C
  • From: Shawn Erickson <email@hidden>
  • Date: Thu, 26 Aug 2010 10:06:48 -0700

On Thu, Aug 26, 2010 at 9:11 AM,  <email@hidden> wrote:
> I want to add Obj-C to classes in a  CPP static library that is used by Mac
> and Windows apps. I have set the compile type to cpp.objc so that the file
> extension can remain .cpp and compile on Windows.  I am #ifdef'ing functions
> that use Cocoa.
>
> My question is memory management. Should functions allocate/release auto
> release pools?

It depends. Autorelease pools are a per thread thing (a stack of pools
could exist per thread). If your methods are being called from the
main thread in an NSApplication derived application then you have an
autorelease pool at the event loop level being managed for you. If
they are being called form secondary threads then you need to ensure
an autorelease pool exists and is drained periodically, assuming  code
running on that thread deals with any objective-c objects.

Now you may want to create nested autorelease pools to further limit
the accumulation of temporary objects even when the AppKit framwork is
managing a top level autorelease pool for you.

Review...

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmAutoreleasePools.html

-Shawn
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Mixing CPP and Obj-C
      • From: email@hidden
References: 
 >Mixing CPP and Obj-C (From: email@hidden)

  • Prev by Date: Re: How to change name and location of "core dump files"
  • Next by Date: Re: Mixing CPP and Obj-C
  • Previous by thread: Re: Mixing CPP and Obj-C
  • Next by thread: Re: Mixing CPP and Obj-C
  • Index(es):
    • Date
    • Thread