Skip to content

Memory not freed when free_after_load is True #246

@jean-emmanuel

Description

@jean-emmanuel

Hi,
I'm having some trouble finding the source of this issue. I'm using pi3d on a linux desktop and I've been able to manage the video memory consumption well : the gpu memory is freed as expected when dereferencing the textures; however, I can't manage to free the RAM where the texture is stored as a numpy array, even when setting the free_after_load flag. Here is a minimal reproduction script, I'm monitoring the actual memory consumption with these two commands:

  •  free -h (ram)
  • glxinfo |grep "available.*memory" (vram)
import pi3d
import numpy
import time

textures = []
memory = 0
display = pi3d.Display.create(w=800, h=600)

# Warning ! adjust this to your card's capability
max_memory = 2048 * 1024 * 1024 # 2048MB


while display.loop_running():

    if memory < max_memory:

        tex = pi3d.Texture(numpy.full((1920,1080,4), dtype='uint8', fill_value=0), free_after_load=True, defer=False, mipmap=False)
        textures.append(tex)

        # tex.file_string points to tex.image -> should be deleted as well
        # (only relevant if texture object is kept somewhere ofc)
        tex.file_string = None

        memory += 1920 * 1080 * 4
        print('Loaded: %iMB' % int(memory / 1024 / 1024.))

    else:

        # uncommenting this frees the vram but not the ram
        # textures = []

        time.sleep(0.1)

Besides the tex.file_string reference I didn't find any living reference to the texture's array that would prevent garbage collection... any thoughts ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions