After working with Jürg on this for the past week, and running some experiments with valgrind and the memory profiler, it appears that what is actually happening is heap fragmentation, which causes the heap to grow. If I run the test case with the printf statment for 12 hours, the heap size remains constant. If I run the normal case setting the radioMenuItem label, the heap grows by about 1 MiB in a 9 hour period.
Looking at the generated C code does not show anything strange, only a call to gtk_menu_item_set_label () with the new text label, which gets freed at the end of the method. So that brings up the question, is there a way of minimizing the amount of heap fragmentation? There are six menu labels which update once per second, and each label will vary between 10 to 36 characters in length. One method I can think of, but cannot seem to figure out the code for, would be to initially create a menu item with a long enough string (say, 64 characters) that I could over-write instead of having to call set_label(), which uses realloc(), like: char *label = radioItem [item].label; char *text = (item == 0) ? FORMAT [item].printf (val1) : FORMAT [item].printf (readable (val1), readable (val2)); do *label++ = *text; while (*text++ != '\0'); // There's no strcpy () ... make our own! The code compiles and runs, but the menu items do not actually update. Is there a signal that needs to be issued to inform the menu that labels have been updated? The other thought would be to periodically run a heap defrag routine, maybe once per minute, but I have not found a function that does that in the API. Bruce On Fri, Jul 6, 2012 at 6:17 PM, Jürg Billeter <j...@bitron.ch> wrote: > > While (owned) is definitely useless here, this should not cause a memory > leak, and in a quick test valac appears to handle this correctly. > > Bruce, if you can provide a self-contained test case, I'll take a closer > look. > > Regards, > Jürg > >
_______________________________________________ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list