Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
New java warning in R2010B

Subject: New java warning in R2010B

From: Jesse Hopkins

Date: 21 Oct, 2010 17:53:04

Message: 1 of 3

Hello,

I've been using Java objects in some GUI's. I recently got a hold of Matlab R2010B, and now I am getting the following warning:

"Warning: Possible deprecated use of set on a Java callback."

The code that I use that generates this warning is:
set(javaTree,'MouseClickedCallback',{@treeClicked,fig},'ToolTipText','Tip: use Alt-Click to edit plotting functions');

Where in this case the javaTree variable is a java object of class javax.swing.JTree.

Does anyone have any insight into this? Will this functionality be disappearing, or is there a new way to do such a thing?

Subject: New java warning in R2010B

From: Yair Altman

Date: 21 Oct, 2010 21:13:03

Message: 2 of 3

"Jesse Hopkins" <na@na.com> wrote in message <i9pum0$j9c$1@fred.mathworks.com>...
> Hello,
>
> I've been using Java objects in some GUI's. I recently got a hold of Matlab R2010B, and now I am getting the following warning:
>
> "Warning: Possible deprecated use of set on a Java callback."
>
> The code that I use that generates this warning is:
> set(javaTree,'MouseClickedCallback',{@treeClicked,fig},'ToolTipText','Tip: use Alt-Click to edit plotting functions');
>
> Where in this case the javaTree variable is a java object of class javax.swing.JTree.
>
> Does anyone have any insight into this? Will this functionality be disappearing, or is there a new way to do such a thing?


Setting a callback directly on the Java "naked" reference has always been discouraged, since it causes memory leaks. See for example: http://mathforum.org/kb/message.jspa?messageID=5950839 , http://www.mathworks.com/matlabcentral/newsreader/view_thread/156388#399260 and even Matlab's official doc: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/set.html#f67-433534 ; note related: http://www.mathworks.com/access/helpdesk/help/techdoc/rn/broifyr-1.html#brrxpv8-1

The solution is to wrap the naked reference with a Matlab handle, as follows (note that this is undocumented and not officially supported, but it has worked this way for many releases already):

hJavaTree = handle(javaTree, 'CallbackProperties');
set(hJavaTree,'MouseClickedCallback',{@treeClicked,fig},'ToolTipText','Tip: use Alt-Click to edit plotting functions');

Yair Altman
http://UndocumentedMatlab.com

Subject: New java warning in R2010B

From: Jesse Hopkins

Date: 22 Oct, 2010 17:14:05

Message: 3 of 3

Yair -

Thanks a million for your reply. Good to know that I've been running with a memory leak for the past couple years :P

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us