When trying to render one video after the other in a circular queue, I’m getting significant memory leaks for some reason.
What would be the best way to make a simple repeating video carousel GUI without causing any leak in memory? Removing references doesn’t seem to do much either, I just hope it isn’t caused within Gstreamer itself.
I tried g_object_unref when wanting to delete the widgets from the main window, without success. The memory just keeps piling on.
Edit: Here’s a very minimal program to demonstrate the issue. This switches between two video files every 5 seconds, but still somehow uses up all of my available memory.
static gboolean switch_video(gpointer user_data)
{
static bool toggle = false;
GtkVideo *video = GTK_VIDEO(user_data);
std::string path = toggle ? "files/video1.mp4" : "files/video2.mp4";
GtkMediaStream *new_media_file = gtk_media_file_new_for_filename(path.c_str());
gtk_video_set_media_stream(video, GTK_MEDIA_STREAM(new_media_file));
gtk_media_stream_play(new_media_file);
g_object_unref(new_media_file);
toggle = !toggle;
return TRUE;
}
static void activate(GtkApplication *app, gpointer user_data)
{
GtkWidget *window = gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW(window), "GTK4 Video Player");
gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
GtkWidget *video = gtk_video_new();
gtk_window_set_child(GTK_WINDOW(window), video);
gtk_widget_show(window);
g_timeout_add_seconds(5, switch_video, video);
}
int main(int argc, char *argv[])
{
GtkApplication *app = gtk_application_new("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
int status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
return status;
}
7