#2378 Aqua: SetPortPenPixPat leak

obsolete: 8.4.16
closed-fixed
5
2008-02-27
2008-01-03
No

This report is copied from a posting by Kevan Hashemi to the Tcl-Mac mailing list.

The following script causes a 1 MByte/min leak in 8.4.16 on MacOS
10.4.10 Intel or PPC, but no leak in 8.4.14 or lower. The code deletes
the last line in a text widget and writes it over again.

destroy .text
set T [text .text -undo 0]
pack $T
proc display {} {
global T
$T delete "end -1 lines" end
set s [clock format [clock seconds] -format {%c}]
$T insert end $s
after 10 display
}
display

Discussion

  • Russell Owen

    Russell Owen - 2008-01-05

    Logged In: YES
    user_id=431773
    Originator: YES

    I have also seen the leak using Aqua Tcl/Tk 8.4.15 on an Intel Mac running 10.4.11

     
  • Daniel A. Steffen

    Logged In: YES
    user_id=90580
    Originator: NO

    I cannot reproduce this leak with 8.5.0 on Leopard (in a -DPURIFY build).
    None of MallocDebug, Leaks Instrument or 'leaks' show any leaked memory during or at the end of process lifetiime, and 'top' does not show any increasing memory usage either.
    How are you measuring the leak?
    please verify that it you still see it with 8.5.0 (and in a -DPURIFY build).

     
  • Nobody/Anonymous

    Logged In: NO

    Does this mean it will never be fixed in the 8.4 branch? That would be disappointing as it is a very serious problem and Python 2.4 and 2.5 do not work well with Tcl/Tk 8.5

     
  • Kevan Hashemi

    Kevan Hashemi - 2008-02-25

    Logged In: YES
    user_id=2019170
    Originator: NO

    I measure the leak by running the above script and watching the application real memory use with the Activity Monitor. The example script creates a 1 MByte/min leak in 8.4.16 on MacOS PPC and Intel runnint 10.3.9 or 10.4.10, but no leak in 8.4.14 or lower. The code deletes
    the last line in a text widget and writes it over again. I just compiled 8.4.18 from source, and I see the leak on PPC, so I assume the problem is still there. I'll try compiling 8.5.1 in a minute.

    Kevan Hashemi

     
  • Kevan Hashemi

    Kevan Hashemi - 2008-02-25

    Logged In: YES
    user_id=2019170
    Originator: NO

    The leak does not occur in 8.5.1. I just tested the above script on Intel and PPC OSX 10.4.11. Memory consumption was 22 to 25 MBytes when I started the script, and 22 to 25 MBytes after 20 minutes. The 1 MByte/minute leak is gone. I am still working on moving over to 8.5 from 8.4, so I'd like very much to see this bug fixed in 8.4.19. Nevertheless, I understand that time is limited, and that 8.5 is the top priority. Kevan Hashemi

     
  • Daniel A. Steffen

    • assigned_to: hobbs --> das
    • summary: Memory leak, at least on MacOS X --> Aqua: SetPortPenPixPat leak
    • status: open --> closed-fixed
     
  • Daniel A. Steffen

    Logged In: YES
    user_id=90580
    Originator: NO

    That was helpful info, thanks.

    Issue reproduced and tracked down to the Carbon SetPortPenPixPat() API used in TkMacOSXSetUpGraphicsPort(): in contrast to the older PenPixPat() (which operates on the current port), SetPortPenPixPat() places a copy of the passed in PixPat into the given port, but does not release that copy when the PenPixPat is reset via PenNormal(), only when the owner port is destroyed.

    Given that every QD drawing operation (with a GC) in TkAqua leads to a call of SetPortPenPixPat(), this can consume a lot of memory (not technically a leak though, as the memory is still referenced from the port, and can be recovered by destroying the port).
    Luckily there are almost not QD drawing operations used by TkAqua anymore (by default), text drawing in 8.4 is one of the only ones you're likely to encounter, which explains your symptoms (note that text drawing in 8.5 uses CG).

    As we are using SetPortPenPixPat() 100% correctly AFAICT, this is really an Apple issue, feel free to nag and yell at them instead...

    Worked around the issue now by changing/restoring current port in TkMacOSXSetUpGraphicsPort() and using PenPixPat() instead of SetPortPenPixPat().

    Fix committed to HEAD and core-8-4-branch.