Should I call dispose on MWArray after I call getField in Java?

3 次查看(过去 30 天)
I am using Java to call matlab. I figured out when I create a MWArray, I need to call dispose explicitly. Then I have this situation:
In the program I call a matlab method many times, every time it returns a MWStructArray m, then I call MWArray mw= m.getField(index) on the MWStructArray m, and print out mw. I will call dispose on m, My question is do I need call mw.dispose also?
A similar question is: I call a matlab method, it return a MWStructArray or MWCellArray m, this object is long live, i will keep it in the memory. But I will call MWArray mw= m.getField(index) many times, is safe to call mw.dispose() every time? will it destroy the data in m? Keep in mind, I want to reuse m again.
Is there any document on exactly how MCR keep/free the object.
Thanks
  1 个评论
Yong
Yong 2013-8-27
by looking the source code of MWStructArray.
public Object get(String paramString, int paramInt)
{
MWArray localMWArray = null;
try
{
localMWArray = getField(paramString, paramInt);
return localMWArray != null ? localMWArray.toArray() : null;
}
finally
{
if (localMWArray != null)
localMWArray.dispose();
}
}
It seems I should call dispose, and it is safe to do so.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Java Package Integration 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by