Clearing java memory in matlab function
I have a matlab function, that calls a java function for displaying GUI.
function [] = Start(x, y)
main.Main.main({x,y});
end
I need to run clear java; command before calling the main function. To delete any data from the previous run.
But in doing so, the input variables x and y are also erased from the memory.
How can I ensure that the memory is clear before running the main function? (Running clear java;
from the command line before calling 开发者_如何学编程Start(x,y)
is not an option).
If x
and y
are defined in the base workspace then you could do something along these lines:
function [] = Start
clear java
x = evalin('caller', 'x');
y = evalin('caller', 'y');
main.Main.main({x,y});
end
However this is a horrible hack and not recommended!
clear java
... clears the java class path, as well as variables in scope, it does not clear "java variables".
If you need to delete data from the previous run, you need to clear that data. If that data is in a Java object then you may need to clear any references to that object.
See http://www.mathworks.com.au/help/matlab/ref/clear.html for more info
精彩评论