[Vala] Help with Memory Leak
- From: Bruce Reidenbach <bereiden gmail com>
- To: vala-list gnome org
- Subject: [Vala] Help with Memory Leak
- Date: Fri, 6 Jul 2012 14:27:02 -0400
Hello all,
I am encountering a memory leak in an appindicator menu. The menu is made
up of several RadioMenuItems that have their labels updated once per
second. I have tracked the memory leak down to the following code, but
cannot seem to be able to make any additional headway. The method "update"
is called from several sources, and specifies the radio item and the values
to update via a const array of FORMAT statements. If I comment out the
code that sets the radio menu item label and un-comment the printf
statement, the leak disappears. The leak is minor -- on the order of about
20 to 30 bytes per invocation -- but over time it adds up.
I'm not sure if this is the correct forum for asking for help, or whether
this is a problem with the gtk+-3.0 or appindicator3-0.1 packages, but I
thought I'd see if anyone has any ideas in the Vala community first.
Thanks,
Bruce
//
-------------------------------------------------------------------------------------
// Make results more readable by appending the appropriate metric unit to
the data
//
-------------------------------------------------------------------------------------
private const string suffix [] = { "bytes", "KiB", "MiB", "GiB", "TiB",
"PiB", "EiB", "ZiB" };
private string readable (float bytes) {
foreach (string s in suffix) {
if (bytes < 1024.0) {
var format = (s == "bytes") ? "%.0f %s" : "%.1f %s";
return format.printf (bytes, s);
}
bytes = bytes / 1024.0f;
}
return "%.1f YiB".printf (bytes);
}
//
-------------------------------------------------------------------------------------
// Menu update
//
-------------------------------------------------------------------------------------
public void update (int item, float pct, float val1, float? val2 = 0.0f) {
var text = (item == 0) ? FORMAT [item].printf (val1)
: FORMAT [item].printf (readable (val1),
readable (val2));
radioItem [item].label = (owned) text; // **** Leaky? ****
//stdout.printf (text + "\n");
var ptr = (int) (pct * 10.0f);
if (selected == item) appIcon.set_icon_full (icons [ptr], NAME);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]