• 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: Cocoa class extension best practice
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa class extension best practice


  • Subject: Re: Cocoa class extension best practice
  • From: Steve Mills <email@hidden>
  • Date: Wed, 16 Oct 2013 11:57:16 -0500

On Oct 16, 2013, at 10:08:03, Ken Thomases <email@hidden> wrote:

> Released to the point of being deallocated?  Deallocation would also be indicated in the history.

#	Address	Category	Event Type	RefCt	Timestamp	Size	Responsible Library	Responsible Caller
0	0x7eb9c160	__NSArrayI	Malloc	1	29:21.944.045	96	AppKit	-[NSMenu itemArray]
1	0x7eb9c160	__NSArrayI	Autorelease	 	29:21.944.054	0	AppKit	-[NSMenu itemArray]
2	0x7eb9c160	__NSArrayI	Release	0	29:30.753.222	0	Foundation	-[NSAutoreleasePool drain]
3	0x7eb9c160	__NSArrayI	Free	0	29:30.753.229	-96	Foundation	-[NSAutoreleasePool drain]

They all appear to be freed, although I was sure in previous runs I saw them only with only 2 history events instead of 4. Something is amiss somewhere (obviously not with the itemArrays, at least for this particular run of the app), because our memory footprint keeps growing, yet there are no leaks other than a few very small (we're talking bytes, not kilobytes) objects that appear to be beyond our control.

So at this point, let's finish this thread by going back to my original question. Is it OK to use the private instance variable _itemArray in NSMenu since the methods we've added are *extensions* of NSMenu and not a subclass? They simply iterate over the array and ask each item for its tag and call the same method on submenus. Below is the way it is now, with [self itemArray] being called, which seems inefficient because it creates an immutable copy of the array. If NSMenu were my own class, I'd definitely use the instance variable for this sort of routine.

- (NSMenuItem*)itemWithTag:(NSInteger)tag searchSubmenus:(BOOL)searchSubmenus depthFirst:(BOOL)depthFirst
{
    if(!depthFirst) {
        id		item = [self itemWithTag:tag];

        if(item)
            return item;
    }

    if(searchSubmenus) {
        for(NSMenuItem* item in [self itemArray]) {
            if([item hasSubmenu]) {
                NSMenuItem*		subitem = [[item submenu] itemWithTag:tag searchSubmenus:searchSubmenus depthFirst:depthFirst];

                if(subitem)
                    return subitem;
            }
        }
    }

    return [self itemWithTag:tag];
}


--
Steve Mills
office: 952-818-3871
home: 952-401-6255
cell: 612-803-6157



_______________________________________________

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: Cocoa class extension best practice
      • From: Dave <email@hidden>
    • Re: Cocoa class extension best practice
      • From: Uli Kusterer <email@hidden>
    • Re: Cocoa class extension best practice
      • From: Fritz Anderson <email@hidden>
    • Re: Cocoa class extension best practice
      • From: Andy Lee <email@hidden>
    • Re: Cocoa class extension best practice
      • From: Charles Srstka <email@hidden>
References: 
 >Cocoa class extension best practice (From: Steve Mills <email@hidden>)
 >Re: Cocoa class extension best practice (From: Kyle Sluder <email@hidden>)
 >Re: Cocoa class extension best practice (From: Steve Mills <email@hidden>)
 >Re: Cocoa class extension best practice (From: Graham Cox <email@hidden>)
 >Re: Cocoa class extension best practice (From: "Mills, Steve" <email@hidden>)
 >Re: Cocoa class extension best practice (From: Graham Cox <email@hidden>)
 >Re: Cocoa class extension best practice (From: Steve Mills <email@hidden>)
 >Re: Cocoa class extension best practice (From: Jens Alfke <email@hidden>)
 >Re: Cocoa class extension best practice (From: Ken Thomases <email@hidden>)
 >Re: Cocoa class extension best practice (From: Steve Mills <email@hidden>)
 >Re: Cocoa class extension best practice (From: Ken Thomases <email@hidden>)

  • Prev by Date: Question about matrix of possibilities
  • Next by Date: Re: Question about matrix of possibilities
  • Previous by thread: Re: Cocoa class extension best practice
  • Next by thread: Re: Cocoa class extension best practice
  • Index(es):
    • Date
    • Thread