Re: GTK free function doesn't appear to have any affect.



On Sat, 15 Jun 2013, dE wrote:

On 06/15/13 14:24, dE wrote:
On 06/15/13 03:35, Chris Vine wrote:
On Fri, 14 Jun 2013 23:03:55 +0530
dE <de techno gmail com> wrote:
On 06/14/13 22:09, Chris Vine wrote:
On Fri, 14 Jun 2013 21:41:05 +0530
dE<de techno gmail com>  wrote:
On 06/14/13 17:02, Matthias Clasen wrote:
On Fri, Jun 14, 2013 at 3:27 AM, dE<de techno gmail com>  wrote:
I was monitoring the memory usage before and after execution of
g_object_unref and gtk_list_store_clear, and it didnt change the
memory usage by a bit.

Is this normal (am I doing it right?)?
What are you monitoring, and how ?

It is i normal that freeing memory does not change the resource
consumption of the process. The freed memory will be available for
reuse by malloc, but malloc does not immediately return the memory
to the OS.
No, filled more than 7GB, swap was at ~350 MB, and then I loaded a
small table which would otherwise take less than 10 MB memory, but
the memory usage increased.
Can you post the smallest compilable program which demonstrates your
problem (run with G_SLICE=always-malloc set), and with particulars
of how you are measuring memory usage?  That should identify if you
are doing something wrong with how you are handling the memory in
your program.

Chris

You can have the whole source code:

http://pastebin.com/4a5DiMsQ

I'd been distributing it around to fix issues.
This isn't going to help I am afraid.

On some general observations on your earlier questions however:

A GtkBuilder object is a plain GObject.  It will be freed by calling
g_object_unref() on it.  That will also cause it to release its
references to the objects it has created.  Whether that will destroy
those created objects depends on whether there are any other
references to them which have been acquired, such as by their having
been put in a container.  If so, then you need to release those other
references as well in order to destroy the created objects and free
their memory.  Top level windows need to have gtk_widget_destroy()
called on them.  If you want to remove a widget from a container or top
level window but keep the container or top level window alive, you can
cause the container to release its reference with
gtk_container_remove().  If you want all containers holding a reference
to a particular GtkWidget to release their references so leading to the
widget's destruction, call gtk_widget_destroy() on the widget.

For plain GObjects, namely those which are not created with a floating
reference (and so are not derived from GInitiallyUnowned/GtkWidget),
to free them you need to have called g_object_unref() on them explicitly
as well as destroy (or remove them from) their container (if any):
except that GtkBuilder will already have done that for you if it
supplies a plain GObject already embedded in a container it has
supplied. For objects derived from GInitiallyUnowned/GtkWidget,
destroying (or removing them from) their container by one of the means
mentioned above is enough.

You may be aware of all that.  If so I am afraid you need to break your
code down to see whether you have discovered a referencing bug (not
likely but possible - I have reported referencing bugs before now), or
you have neglected to release something somewhere.

Chris

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, &current );
       for ( j = 0 ; j < COLS ; j++ ) {
gtk_list_store_set ( store , &current , 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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]