• 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: static objects "autoreleased with no pool in place - just leaking"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: static objects "autoreleased with no pool in place - just leaking"


  • Subject: Re: static objects "autoreleased with no pool in place - just leaking"
  • From: m <email@hidden>
  • Date: Fri, 13 Feb 2004 00:31:45 -0800

Yes, that would work but more cumbersome to maintain (static var declaration and accessor multiplied by the number of statics).

In my case, I'm not trying to emulate class variables, rather I'm setting up a host of colors, fonts, etc. all in one place, that can be referred to symbolically (that is, directly, not through an accessor). This also has the advantage that all values are co-located for easy comparison.

So for example, at the top of my source file:

static NSColor* sLabelColor1 = [NSColor colorWithDeviceRed: 0.0 green:0.0 blue:0.0 alpha:1.0];
static NSColor* sLabelColor2 = [NSColor colorWithDeviceRed: 1.0 green:0.0 blue:0.0 alpha:1.0];
static NSColor* sLabelColor3 = [NSColor colorWithDeviceRed: 0.0 green:0.0 blue:1.0 alpha:1.0];
static NSColor* sLabelColor4 = [NSColor colorWithDeviceRed: 1.0 green:0.0 blue:1.0 alpha:1.0];
static NSImage* sBusyCursorImage = [NSImage imageNamed:@"busy.tif"];
static NSImage* sHandCursorImage = [NSImage imageNamed:@"hand.tif"];
etc.

This is the kind of thing that I did all the time in C++, it's hard to believe that no one has figures out a clean way to do it in Obj-C++.

_murat


On Feb 13, 2004, at 12:06 AM, j o a r wrote:

If something hurts, then you should stop doing it... There is more than one way to skin a cat, as they say.

Have a look at my last reply for an alternative solution on this topic.

From joar's last reply:
Usually what you would do is something like this:

+ (NSMutableDictionary *) myStaticDictionary
{
static NSMutableDictionary *theStaticDict = nil;

if (theStaticDict == nil)
{
theStaticDict = [[NSMutableDictionary alloc] init];
}

return theStaticDict;
}

...as static variables are often used to "emulate" class variables.
In the example above the code would typically be executed where an autorelease pool has already been set up.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: static objects "autoreleased with no pool in place - just leaking"
      • From: Public Look <email@hidden>
    • Re: static objects "autoreleased with no pool in place - just leaking"
      • From: j o a r <email@hidden>
References: 
 >static objects "autoreleased with no pool in place - just leaking" (From: m <email@hidden>)
 >Re: static objects "autoreleased with no pool in place - just leaking" (From: j o a r <email@hidden>)
 >Re: static objects "autoreleased with no pool in place - just leaking" (From: m <email@hidden>)
 >Re: static objects "autoreleased with no pool in place - just leaking" (From: j o a r <email@hidden>)
 >Re: static objects "autoreleased with no pool in place - just leaking" (From: m <email@hidden>)
 >Re: static objects "autoreleased with no pool in place - just leaking" (From: j o a r <email@hidden>)

  • Prev by Date: Re: Java bridge: Java method with 2 arguments
  • Next by Date: Re: static objects "autoreleased with no pool in place - just leaking"
  • Previous by thread: Re: static objects "autoreleased with no pool in place - just leaking"
  • Next by thread: Re: static objects "autoreleased with no pool in place - just leaking"
  • Index(es):
    • Date
    • Thread