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

3 vues (au cours des 30 derniers jours)
Yong
Yong le 26 Août 2013
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 commentaire
Yong
Yong le 27 Août 2013
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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Java Package Integration dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by