The problem is not likely to be loading the fonts (which are already
cached), but in their rendering.

Here's a little program that loads the font only once, but renders "hello
world" 2500 times, then shows the result. It prints out the total memory
before and after the rendering. Play with different fonts and see if you
can discover anything. I think 2,500 renderings will be enough to reveal
something, but you may have to adjust.

It also shows the results. If you're not running under a GUI, you should
comment out the last line in the program.

-tk

On Fri, Sep 9, 2016 at 3:10 PM, Allan <weewx2...@warpspeed.dyndns.dk> wrote:

> Den 10-09-2016 kl. 00:00 skrev Thomas Keffer:
>
>> Hi, Allen
>>
>> Your conclusions do not surprise me. This is not the first memory leak
>> we have found in the underlying operating system. Usually we can work
>> around the leaks by caching... something.
>>
>> Right now, weewx uses a cache for TrueType fonts. Which font is causing
>> the problems?
>>
>>
> I have only changed the font path in skin.conf
> 5 lines refering to the same font - changed from/to this:
>
> /usr/share/fonts/truetype/freefont/FreeMonoBold.ttf
>
> /usr/share/fonts/gnu-free/FreeMonoBold.ttf
>
>
> nothing else.
>
>
>   Allan.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "weewx-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to weewx-user+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to weewx-user+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
import resource
import os

try:
    from PIL import Image, ImageDraw, ImageFont
except ImportError:
    import Image, ImageDraw, ImageFont


def show_mem(msg):
    """Calculate and print memory usage"""        
    page_size = resource.getpagesize()

    pid = os.getpid()
    procfile = "/proc/%s/statm" % pid
    mem_tuple = open(procfile).read().split()
    
    # Unpack the tuple:
    (size, resident, share, text, lib, data, dt) = mem_tuple
    
    mb = 1024 * 1024
    
    size_mb     = float(size)     * page_size / mb 
    resident_mb = float(resident) * page_size / mb
    share_mb    = float(share)    * page_size / mb
    
    print "*** %s ***" % msg
    print "size=     %.1f MB" %size_mb
    print "resident= %.1f MB" % resident_mb
    print "share=    %.1f MB" % share_mb
    print

show_mem("BEFORE RENDERING")

image = Image.new("RGB", (512,512), "black")
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("FreeMonoBold.ttf", 12)

for y in range(0,500,10):
    for x in range(0,500,10):
        draw.text((x,y), "hello world", font=font)

show_mem("AFTER RENDERING")

# Comment this out if not running under a GUI:
image.show()

Reply via email to