File: pygadgets-products/unzipped/_PyClock/Clock/_MacMemoryLeak/SUMMARY-CONCLUSIONS.txt

Just on Mac OS, using a PNG image for the clock face can 
leak memory so badly as to kill the computer by the end 
of the day if the analog dislay is left open.  Findings:

1) It doesn't matter whether the code deleted and recreates
clock hands, deletes and recreates the entire cnavas, or
simply moves clock hands by changing their coordinates.

2) It doesn't matter whether PIL is used or not; it's not 
required for PNGs in 8.6, but is in in Tk 8.5.

3) It doesn't matter whether Tk 8.6 or 8.5 is used;
8.5 leaks about 8M per 5 seconds; 8.6 leaks less at 
just 3M per 5 seconds but this is still unusable.

4) It doesn't matter is Python's cyclic garbage collector
is called forcibly.

5) It doesn't happen at all if a GIF or JPEG image is used;
in fact, this case is the same as using no photo at all.

6) It doesn't seem to happen on Windows for any image type.

This is clearly a Tk bug, in both 8.5 and 8.6, related 
to display of PNG photos on a Canvas hosting animations.
There is no workaround in Python code; this occurs in 
the Tk C library layer below it.

To address this:

A) A GIF or JPEG is used as the default image, to
   avoid issues on Macs
B) Mac users are advised to avoid PNG images in the 
   Readme.txt and PyGadgets_configs.py files, and Help
C) Mac users get a popup warning once if the image
   is set to a PNG, and a GIF is substituted
D) PIL is still used if present, as it's not 
   relevant to the leak, and supports other 
   image types on other platforms

Later, also:
E) Skip screen updates altogether when minizmized,
   to limit both memory and CPU usage

Popup text
"""
Warning: you've requested a PNG image for the clock 
face, but this can cause extreme memory leaks on 
Mac OS, which are bad on El Capitan, and worse on 
Sierra.  This is due to a bug in the Tk GUI toolkit 
underlying PyPhoto, and cannot be repaired at the 
Python level.

To avoid problems, a default GIF has been used.
Please change your config file to use a GIF or 
JPEG image instead.  The PyPhoto gadget (or Mac's 
Preview) can be used to shrink and save your image
in either the GIF or JPEG recommended formats.
In PyPhoto, zoom out with 'O' and save with 'W'
using a ".gif" or ".jpg" filename extension.
"""



[Home page] Books Code Blog Python Author Train Find ©M.Lutz