c - Has Vala memory leak when building shared library? -


will vala code memory leak when built shared library (.so)?

vala:

namespace test {     public static string info(string name){         return "hello " + name;     } } 

source code (valac -c)

gchar* test_info (const gchar* name) {     gchar* result = null;     const gchar* _tmp0_ = null;     gchar* _tmp1_ = null;     g_return_val_if_fail (name != null, null);     _tmp0_ = name;     _tmp1_ = g_strconcat ("hello ", _tmp0_, null);     result = _tmp1_;     return result; } 

compilation: valac --library=test -h test.h "test.vala" -x -fpic -x -shared -o test.so

i surprised no memory deallocation in test_info.

  • will g_strconcat store allocated memory in global variable (possible thread-local)?
  • will memory leak if call test_info external programm miltiple times without deallocation?

i sorry possible simple question, new in vala (my primary experience in area of go, python, c++ , etc)

your code return owned string, caller responsible memory deallocation.

if call library function vala compiler make sure deallocated.

if call c should read glib documentation g_strconcat:

concatenates of given strings 1 long string. returned string should freed g_free() when no longer needed.

i recommend read:

see this question (which genie, valas "sister language" though).


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -