Brian Lavender
Sun, 07 Mar 2010 12:08:29 -0800
I am attempting to create a g_ptr_array_new_with_free_func. It appears that the memory is not being free after calling g_ptr_array_free(myAry, TRUE);
Shouldn't it release the memory for all the elements?
GLib Memory statistics (successful operations):
blocks of | allocated | freed | allocated | freed | n_bytes
n_bytes | n_times by | n_times by | n_times by | n_times by | remaining
| malloc() | free() | realloc() | realloc() |
===========|============|============|============|============|===========
64 | 0 | 1 | 1 | 0 | +0
508 | 3 | 0 | 0 | 0 | +1524
2040 | 1 | 0 | 0 | 0 | +2040
2500 | 1 | 0 | 0 | 0 | +2500
GLib Memory statistics (failing operations):
--- none ---
Total bytes: allocated=6128, zero-initialized=6064 (98.96%), freed=64 (1.04%),
remaining=6064
#include <glib.h>
#include "types.h"
#include "rand.h"
#include "print.h"
void mydestroy(gpointer myInd) {
g_slice_free1(sizeof(individual), myInd);
//g_free(myInd);
}
int main() {
GPtrArray *myAry;
GRand *myRand;
individual *theInd;
guint i;
g_mem_set_vtable(glib_mem_profiler_table);
g_atexit(g_mem_profile);
myAry = g_ptr_array_new_with_free_func(mydestroy);
// Initialize the random number generator
myRand = g_rand_new();
// Add some individuals to the array.
for (i=0; i<5;i++) {
makeRandIndV1(myRand, &theInd);
g_ptr_array_add(myAry, theInd);
}
// print them out
for (i=0; i<5;i++) {
theInd = g_ptr_array_index(myAry, i);
print_individual(theInd );
}
// free the array.
g_ptr_array_free(myAry, TRUE);
return 0;
}
--
Brian Lavender
http://www.brie.com/brian/
"There are two ways of constructing a software design. One way is to
make it so simple that there are obviously no deficiencies. And the other
way is to make it so complicated that there are no obvious deficiencies."
Professor C. A. R. Hoare
The 1980 Turing award lecture
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list