Mac::Leak

| | Comments (0)
In Mac OS, one would get the data out of an Apple event AEDesc object by merely returning the dataHandle portion of the struct. It's a Handle object.

In Mac OS X, however, one must copy the data to a new Handle object.

So when porting Mac::Carbon to Mac OS X, I made the change, and didn't think about the fact that in Mac OS X, the caller would now be responsible for disposing the Handle object that was returned. Yikes. Memory leaks abound.

Most Mac::Carbon programs I use don't really stick around. Even when they do, such as with my happening script that sets my iChat status, the amount of data that was being leaked was pretty small. The name and artist of the current track, etc.

But then I added functionality to the script so it would change my iChat account icon to the album cover of the track I am listening to. So instead of 100 bytes or so, I was now leaking as much as 250K or so, every 10 seconds. That adds up pretty quick.

I have a temporary fix (manually disposing of the Handle object), but I need a more permanent solution. Matthias (original author of Mac::AppleEvents, MacPerl, etc.) gave me some good ideas, and I'll be working on it soon.

I think I'll use some XS tricks to make a new data type, XAEDesc, which will contain both the AEDesc and a Handle, so instead of creating a Handle each time, the data is transferred to and from the Handle in the XAEDesc. When the AEDesc is destroyed, its corresponding Handle will be disposed of automatically, like it was previously (by modifying AEDisposeDesc to also call DisposeHandle). use.perl.org

Leave a comment

<pudge/*> (pronounced "PudgeGlob") is thousands of posts over many years by Pudge.

"It is the common fate of the indolent to see their rights become a prey to the active. The condition upon which God hath given liberty to man is eternal vigilance; which condition if he break, servitude is at once the consequence of his crime and the punishment of his guilt."

About this Entry

This page contains a single entry by pudge published on April 26, 2004 2:41 PM.

Another Caucus, Another Delegate was the previous entry in this site.

Kerry's Turn is the next entry in this site.

Find recent content on the main index or look in the archives to find all content.