Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Event Handler UPP question



On Aug 26, 2003, at 3:44 PM, Bryan Pietrzak wrote:
On Tuesday, August 26, 2003, at 05:22 PM, Bob Sabiston wrote:
Do the calls to NewEventHandlerUPP() reserve memory that I should be freeing? When should I free it? If the function that installs the handlers gets called many times, do I have a memory leak?

Yes you probably have a leak.

Leaks pre-MacOSX. No leak on MacOSX. Compare the values of handlerUPP and MyHandler in your sample running on X.

You only need one UPP for any callback. I use a static variable and do this:

{
static EventHandlerUPP handlerUPP = NewEventHandlerUPP(MyHandler);

verify_noerr(InstallApplicationEventHandler(handlerUPP, GetEventTypeCount(events), events, (void *) this, NULL));
}

There's a macro for this in CarbonEvents.h:

/*
You can use the following macro in your code to allow you to set up an
event handler lazily. You pass the name of your event handler in. You should
use this with caution on Mac OS 9 systems since it could cause heap fragmentation.
*/
#define DEFINE_ONE_SHOT_HANDLER_GETTER( x ) \
EventHandlerUPP Get ## x ## UPP() \
{ \
static EventHandlerUPP sHandler = NULL; \
\
if ( sHandler == NULL ) \
sHandler = NewEventHandlerUPP( x ); \
\
return sHandler; \
}
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.
References: 
 >Re: Event Handler UPP question (From: Bryan Pietrzak <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.