Issue #34 resolved

Memory leak with pygame.transform functions

illume
created an issue

== Victor Freire, 2009-06-14 13:52:40 -0700

{{{ Created attachment 24 Code demonstrating the leak and the image used.

When using the following pygame.transform functions: scale(), smoothscale() and flip(), memory leaks occur.

Scaling a texture a hundred times per frame consumes a LOT of memory, rendering me unable to use such functions in my game.

I've attached a rar with the code that causes this and the image used.

Operating System: Windows XP SP3 Python version: 2.6.1 Pygame 1.8.1 (the package available at the download section) }}}


Attachments: [[http://www.pygame.org/old_bug_attachments/24/leaktest.rar| leaktest.rar]]

== illume, 2009-06-28 21:44:16 -0700

{{{ With pygame 1.9.0rc1, and python2.5.2 on OSX I can not reproduce this.

Maybe it is a windows, or python2.6 specific bug, or perhaps it has been fixed.

Are you able to try this out with a new pygame?

Binaries here: http://thorbrian.com/pygame/builds.php }}}


== Victor Freire, 2009-06-30 18:30:25 -0700

{{{ I have been able to bypass this in my game by reusing the same surface, not creating a new temporary one for each loop iteration.

I've tested this in 2.5.2 so it's not only in 2.6.

I'll try the new pygame version when I get some spare time. }}}


== Victor Freire, 2009-06-30 18:45:11 -0700

{{{ Created attachment 25 Leak 'workaround' and another leak case

In this .rar there is a 'workaround' for the leak and a sligthly different test case in which leaking also occurs.

Tested with the original configuration. }}}


Attachments: [[http://www.pygame.org/old_bug_attachments/25/Leaktests.rar| Leaktests.rar]]

Comments (4)

  1. illume reporter
    • changed status to open
    • changed milestone to 1.9.2

    The test appears to use pygame.transform.scale when it leaks.

    I made this test case from the one given. Then testsed it on OSX, and it does not leak memory. The memory stays between 20MB and 22MB according to activity monitor.

    Stand alone test case (needs testing in windows XP (or windows Vista/7).

    import pygame, pygame.examples, time, os
    pygame.init()
    main_dir = os.path.split(os.path.abspath(pygame.examples.__file__))[0]
    data_dir = os.path.join(main_dir, 'data')
    image_path = os.path.join(data_dir, "arraydemo.bmp")
    
    screen = pygame.display.set_mode((640, 480), 0, 32)
    slice_h = 40
    test_tile = pygame.image.load(image_path).convert()
    slicescaled = pygame.Surface((1, slice_h))
    
    going = True
    while going:
        going = pygame.QUIT not in [e.type for e in pygame.event.get()]
    
        screen.fill((0, 0, 0)) #clear screen
        for x in xrange(100):
            texoffset = x
            slicepiece = pygame.Surface((1, 128))
            slicepiece.blit(test_tile, (0,0), (texoffset, 0, 1, 128))
            pygame.transform.scale(slicepiece, (1, slice_h), slicescaled)
            screen.blit(slicescaled, (x, 10))
        pygame.display.flip()
        pygame.time.wait(10)
    pygame.quit()
    
  2. Log in to comment