I have attached a simple test program that seems to show that there is a memory 
leak in texture creation.

The program creates an actor, displays it on the screen, and then destroys it 
once per second.  If the actor is created by cloning an existing actor, the 
memory usage of the program stays constant.  If the actor's texture is created 
from scratch each time, the memory consumption of the program grows steadily.

This behavior is present in at least 0.8.8 and 1.0.0.


      
#include <clutter/clutter.h>

ClutterActor *real_actor = NULL;
ClutterActor *actor = NULL;
ClutterStage *stage;

static int
update_actor(void *arg)
{

	printf("update\n");

	if (actor) {
		clutter_actor_hide(actor);
		clutter_actor_destroy(actor);
	}

#ifdef LEAK
	actor = clutter_texture_new_from_file("redhand.png", NULL);
#else
	actor = clutter_clone_new(real_actor);
#endif

	clutter_container_add_actor(CLUTTER_CONTAINER(stage), actor);
	clutter_actor_show_all(CLUTTER_ACTOR(stage));

	return (1);
}

int
main(int argc, char *argv[])
{
	clutter_init(&argc, &argv);

	stage = (ClutterStage *) clutter_stage_get_default();

	real_actor = clutter_texture_new_from_file("redhand.png", NULL);
	clutter_container_add_actor(CLUTTER_CONTAINER(stage), real_actor);

	g_timeout_add(1000, update_actor, NULL);

	clutter_main();

	return (0);
}

Reply via email to