我的程序漏了。在低级代码中,我使用Julius提供的所有工具释放内存。但我想确定这是我的问题,而不是代码。那么这段代码会自然泄漏吗? (循环中的多重识别,使用相同的指针)。
SREngineJulius *julius_pointer;
int iter = 10; //some number
for(int i = 0; i <= iter; i++){
julius_pointer= new SREngineJulius();
julius_pointer->InitSREngine(jconf);
julius_pointer->Callbacks();
julius_pointer->DynamicAddCommands(palavras2,"|",0);
buffering = julius_pointer->Audio_Buffering(audio_buffer, maxlen, 0,1);
result = julius_pointer->NotifyCallbackLoop("nao_interessa_nada");
julius_pointer->~SREngineJulius();
delete julius_pointer;
}
答案 0 :(得分:2)
您不需要动态分配引擎。只需将其用作局部变量:
int iter = 10; //some number
for(int i = 0; i <= iter; i++){
SREngineJulius julius_engine;
julius_engine.InitSREngine(jconf);
julius_engine.Callbacks();
julius_engine.DynamicAddCommands(palavras2,"|",0);
buffering = julius_engine.Audio_Buffering(audio_buffer, maxlen, 0,1);
result = julius_engine.NotifyCallbackLoop("nao_interessa_nada");
// SREngineJulius destructor is called automatically when the variable julius_engine goes out of scope in each iteration
}
如果在这些更改后仍有内存泄漏,则泄漏位于循环内部调用的SREngineJulius方法之一内。