Calling g_queue_pop_tail 100000 times after calling g_queue_push_head 100000 times can not release memory?

I am running the following code on Ubuntu 20.04.4 LTS,but can not release memory after pop data from the double-ended queue.

// gcc glib_test.c -o g_t `pkg-config --cflags --libs glib-2.0`
#include <stdio.h>
#include <glib.h>

#define TEST_NUM 500000

void main()
{
    gint e_len = 0,i = 0; 
    gpointer e = NULL; 
    GQueue *deque = g_queue_new();

	do { 
        usleep(1000);

        e_len = rand() % 4096;
        e = g_malloc (e_len); 
        for(i = 0; i < TEST_NUM; i++)
        {
            g_queue_push_head(deque,e); 
            printf("after push. queue_length %d\n",g_queue_get_length(deque)); 
        } 
        for(i = 0;i < TEST_NUM; i++)
        {
            g_queue_pop_tail (deque); 
            printf("after pop. queue_length %d\n",g_queue_get_length(deque)); 
        }        

        if (e_len) g_free (e);  
	} while (1);
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.