[Vala] Threads with return value... Isn't this a memory leak?
- From: Marco Trevisan (Treviño) <mail 3v1n0 net>
- To: vala-list gnome org
- Subject: [Vala] Threads with return value... Isn't this a memory leak?
- Date: Tue, 04 Jan 2011 16:30:38 +0100
Consider this simple vala code, which uses some threads with return
value... Since int[] can't be a generics, I need to use an int pointer
for using an integer array as retourn value...
It works as expected, but... If you look at the generated C code, the
pointer returned by g_thread_join (t) is never free'd.
The same happens using strings, but not with more complex object (like
GLib.Array, for example)... Is this a bug?
Why is this happening?
-------
int main(string[] args) {
const int nthreads = 5;
List<unowned Thread<int*>> threads = new List<unowned Thread<int*>>();
for (int i = 0; i < nthreads; ++i) {
try {
unowned Thread<int*> th = Thread.create<int*>(thread_run, true);
threads.append(th);
} catch (ThreadError e) {}
}
int thi = 0;
foreach (var t in threads) {
int *ret = t.join();
print(@"[$(thi++)] $(ret[0]) - $(ret[1]) - $(ret[2])\n");
}
}
int* thread_run() {
int a = (int) GLib.Random.next_int();
int b = (int) GLib.Random.next_int();
int c = (int) GLib.Random.next_int();
return new int[] {a, b, c};
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]