• 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: Old NeXT code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Old NeXT code


  • Subject: Re: Old NeXT code
  • From: Kenny Leung <email@hidden>
  • Date: Sat, 10 Sep 2005 23:36:04 -0700


On Sep 10, 2005, at 7:08 PM, Ken Shmidheiser wrote:

I have been attempting to compile in Xcode a 1992 vintage NeXT project found here:

typedef struct {
        NXColor        background;
        NXColor        text;
    } squareColor;

NXColor was a struct, I think. NSColor is now an object. You cannot declare an object statically, so you will have to change it to this:



typedef struct { NSColor *background; NSColor *text; } squareColor;

This also complicates things a bit in terms of memory management. Depending on how squareColor is declared, (if it's malloc'd or not) you may or may not have had to free it.

Now, however, you have to worry about the NSColors it contains, or risk leaking them. You need to remember to release the NSColors when you're done with them.

Scenario 1: easier to remember
- (void)blah
{
    squareColor *colors;

    colors = malloc(sizeof(squareColor));
    colors->background = [[NSColor redColor] retain];
    colors->text = [[NSColor blackColor] retain];
... do some stuff ...
    free(colors);
    [colors->background release];
    [colors->background release];
}


Scenario 2: easier to forget

- (void)blah
{
    squareColor colors;

    colors.background = [[NSColor redColor] retain];
    colors.text = [[NSColor blackColor] retain];
... do some stuff...
    [colors.background release];
    [colors.background release];
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Old NeXT code (From: Ken Shmidheiser <email@hidden>)

  • Prev by Date: IP address from NSFileHandle?
  • Next by Date: Re: IP address from NSFileHandle?
  • Previous by thread: Re: Old NeXT code
  • Next by thread: A simple launcher program
  • Index(es):
    • Date
    • Thread