Re: Will this create a memory leak? Can't determine from top.

Bartek Kostrzewa wrote:
Should I define an array of char pointers
*message[TABLE_SIZE][TABLE_SIZE] to hold the pointers created by
g_strdup_printf or would that just be a waste of memory?

   I guess you want to free the string when the object emmiting the
signal is finalized, in that case you can use a function like
g_object_weak_ref like so:

free_signal_string (gpointer data,
                    GObject *where_the_object_was)
    /* free the string here */
    g_free (data);

    string = g_strdup_printf (...);
    g_signal_connect(button[i][j], "clicked",
                     G_CALLBACK(print_position), string);

    /* Hook onto buttons finalization */
    g_object_weak_ref (G_OBJECT (button[i][j]),
                       free_signal_string, string);

Ofcourse you could think up a million solutions for this
problem and they could all be good.


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