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 Tuesday, August 26, 2003, at 05:22 PM, Bob Sabiston wrote:

Hello,
I have a question about the way EventHandler UPP's work. In order to install an event handler, say to a window, you have to make a UPP for the handler function. Then you call InstallEventHandler to attach it to the window. Later, if you need to, you can remove the handler by using the Ref that is returned from the Install.

In my program, there is a point where I remove the handlers for a window, and I install different ones. This can happen several times during the program's running. My question:

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.

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));
}

That way only one UPP is ever created for MyHandler

I don't worry about freeing it as it'll go away when my app's address space is torn down.

Bryan
_______________________________________________
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: 
 >Event Handler UPP question (From: Bob Sabiston <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.