[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] question about appleevent



pudge@pobox.com (Chris Nandor) writes:
>At 04.31 9/17/97, Georges Martin wrote:
>>>AEDisposeDesc $evt;
>>>AEDisposeDesc $rep;
>>
>>It's far beyond my knowledge of the Toolbox and MacPerl, but can't this
>>kind of "garbage collection" be done by a "END" routine ?
>
>Yes, but it can go there.  If this were OOP, then it could go in the
>DESTROY sub.  But it can go anywhere you want it.
>
>Regardless, I have never found a real need for AEDisposeDisc.  As Perl does
>its own garbage collection, wouldn't AEDisposeDisc be unneccessary for a
>script that didn't have a long run time?

The two of you have touched a tricky issue, and one that is apparently not that
well discussed in the existing documentation (In the course of a general
revision of the toolbox pods, I plan to write an overview document discussing
this and other issues).

The basic concept of memory management in the toolbox modules is:

  The raw toolbox interfaces in MacPerl do *not* automatically dispose memory
  that a C programmer would dispose manually.

An AEDesc consists of a Perl data structure (a reference, blessed into package
AEDesc, referencing an AEDesc SV) and a memory manager handle containing the
actual data of the AEDesc.

The blessed reference is garbage collected but the handle *ISN'T*. You need
to call AEDisposeDesc, or you have a memory leak.

On the other hand, the memory allocated to the ToolboxEvent passed to the
MacPerl event handlers *is* automatically disposed, as C programmers wouldn't
allocate memory there. Handles returned from the resource manager are disposed
by the toolbox when the file is closed, so there is no leak there, either.

The reason for this policy is that an underlying toolbox object might have a
longer lifetime than the Perl object wrapping it, so since I couldn't exclude
that possibility in general, I preferred to apply a consistent, if somewhat
inconvenient policy everywhere.

Matthias

-----
Matthias Neeracher   <neeri@iis.ee.ethz.ch>   http://www.iis.ee.ethz.ch/~neeri
  "... after a few more flashes in the pan, we shall hear very little more
  of Edison or his electric lamp. Every claim he makes has been tested and
  proved impracticable." -- _New York Times_, January 16, 1880

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch