Re: GTK free function doesn't appear to have any affect.
- From: dE <de techno gmail com>
- To: gtk-app-devel-list gnome org
- Subject: Re: GTK free function doesn't appear to have any affect.
- Date: Sun, 16 Jun 2013 12:28:52 +0530
On 06/16/13 00:40, Allin Cottrell wrote:
On Sat, 15 Jun 2013, dE wrote:
On 06/15/13 14:24, dE wrote:
Yes, I realized that over time, but there appears to be something
wrong with g_object_unref or in general all GTK free functions on my
system.
In this piece of code --
#include <stdio.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#define COLS 300
void main ( ) {
gtk_init( NULL, NULL );
int i, j;
char *temp;
GtkTreeIter current;
GType *str_type = g_malloc (sizeof (GType) * COLS);
for (i = 0; i <= COLS; i++)
str_type [i] = G_TYPE_STRING;
GtkListStore *store = gtk_list_store_newv (COLS, str_type);
g_free (str_type);
for (i = 0; i < 300000 ; i++) {
gtk_list_store_append ( store, ¤t );
for ( j = 0 ; j < COLS ; j++ ) {
gtk_list_store_set ( store , ¤t , j , "Hello world
Hello world Hello world!", -1 );
}
}
printf ( "freeing after 10 seconds\n" );
sleep (10);
free_ptr ( store );
printf ("Now freed\n");
sleep (10);
}
free_ptr ( GtkListStore *store ) {
gtk_list_store_clear (store);
g_object_unref( G_OBJECT (store) );
}
Calling free_ptr ( store ); increases memory usage, even during the
last 10 second free period. It'll take at most 7GB of memory.
Here there're no GtkWidgets involved. GtkListStore inherits directly
from GObject.
Is this piece of code itself ok?
Certainly not. "void main()" is not valid C for a start (main must
return int), then the first loop runs off the end of the str_type
array...
Allin Cottrell
Apart from that, in the free_ptr? Does memory get freed for anyone else?
#include <stdio.h>
#include <gtk/gtk.h>
#define COLS 200
void free_ptr ( GtkListStore * );
int main ( ) {
gtk_init( NULL, NULL );
int i, j;
char *temp;
GtkTreeIter current;
GType *str_type = g_malloc (sizeof (GType) * COLS);
for (i = 0; i < COLS; i++)
str_type [i] = G_TYPE_STRING;
GtkListStore *store = gtk_list_store_newv (COLS, str_type);
g_free (str_type);
for (i = 0; i < 300000 ; i++) {
gtk_list_store_append ( store, ¤t );
for ( j = 0 ; j < COLS ; j++ ) {
gtk_list_store_set ( store , ¤t , j , "Hello world
Hello world Hello world!", -1 );
}
}
printf ( "freeing after 10 seconds\n" );
sleep (10);
free_ptr ( store );
printf ("Now freed\n");
sleep (10);
return 0;
}
void free_ptr ( GtkListStore *store ) {
gtk_list_store_clear (store);
g_object_unref( G_OBJECT (store) );
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]