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

조회 수: 3 (최근 30일)
Yong
Yong 2013년 8월 26일
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