The erl_interface library really uses a kind of reference counting system to track distributed ETERM structures. Therefore, if you write:
ETERM *t_arr[2]; ETERM *t1; t_arr[0] = erl_mk_atom("hello"); t_arr[1] = erl_mk_atom("world"); t1 = erl_mk_tuple(&t_arr[0],2);
You have created three (3) Erlang members (ETERM). Now, if you call: erl_free_term (t1), you only free the tuple, not the other two ETERMs. To free all allocated memory, you would have to call:
erl_free_term(t_arr[0]); erl_free_term(t_arr[1]); erl_free_term(t1)
To avoid all these calls in erl_free_term (), you can use: erl_free_compund (). He is "deeply" free from all ETERM. Thus, the above can be accomplished using:
erl_free_compund(t1)
Thus, this procedure allows you to write in a more compact form, where you do not need to remember links to all ETERM subcomponents. Example:
ETERM *list; list = erl_cons(erl_mk_int(36), erl_cons(erl_mk_atom("tobbe"), erl_mk_empty_list())); ... erl_free_compound(list);
Refresh . To check if you really exempt all creation conditions, you can use this code snippet ( original entry manually :
long allocated, freed; erl_eterm_statistics(&allocated,&freed); printf("currently allocated blocks: %ld\n",allocated); printf("length of freelist: %ld\n",freed); erl_eterm_release();
( answer accepted here )
source share