【发布时间】:2015-07-14 12:04:20
【问题描述】:
这个 Vala 代码在构建为共享库 (.so) 时会发生内存泄漏吗?
瓦拉:
namespace test {
public static string info(string name){
return "Hello " + name;
}
}
源代码(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;
}
编译:valac --library=test -H test.h "test.vala" -X -fPIC -X -shared -o test.so
我对@987654325@ 中没有内存释放感到惊讶。
-
g_strconcat是否会将分配的内存存储在全局变量中(可能是线程本地的)? - 如果我从外部程序多次调用
test_info而不解除分配,是否会发生内存泄漏?
我很抱歉这个可能很简单的问题,但我是 Vala 的新手(我在 Go、Python、C++ 等领域的主要经验)
【问题讨论】: