Hi,

I have implemented a list based SVG menu that allows me to have a sub menu structure, whereby the I can traverse down several levels, then display some SVG based control.
I am using this as a Settings Application to alter say a volume level or a user name/password
eg

<TopLevel_SVGMenu>
Option1 --------> <SubMenuOption1_SVGMenu>
Option2 Option1 ------------------<some SVG based control>
Option3 Option2

To try and keep my memory usage down, I create the Submenus and controls only when activated.
When I traverse back up the tree, I set the previous level (Control / SVGMenu) to null.

However I have observed when running the Java Me WTK 2.2.5 memory Profiler when I set the SVGMenu to null, the amount of memory the application asks for starts to increase.

After writing a simple test application based on the SVGProject from the Nokia forum examples)
I have found that if I add the following functionality to my svgMenu, when I create it, the subsequent freeing of this resource (when i set it to null) starts the memory leak.

//please see the code comment
public SVGMenu getSvgMenu() {
if (svgMenu == null) {

svgMenu = new SVGMenu(getSvgImage1(), getDisplay());
svgMenu.setTitle("svgMenu");
svgMenu.addCommand(SVGMenu.SELECT_COMMAND);
svgMenu.setCommandListener(this);
// *** If I remove these my application doesn't leak memory when I set the svgMenu to NULL
svgMenu.addMenuElement("menuItem_1");
svgMenu.addMenuElement("menuItem_2");
svgMenu.addMenuElement("menuItem_3");
}
return svgMenu;



I am unsure if I am not freeing this resource in the correct manner, the API doesn't seem to have anything related to helping free the memory on clean up.
I would appreciate if anyone could give me any guidance or help on how to clean this up properly, as the leaking memory eventually brings my application to a standstill.

Thanks in advance
GuusDavidson

PS.
I have included a a copy of my test application + the two SVG menuitem code (I have removed the references to the images, as this made loading faster in the emulator,

PPS. I have been running this under the WTK2.2.5 so to use the memory profiler.

package hello;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.m2g.SVGEventListener;
import javax.microedition.m2g.SVGImage;
import org.netbeans.microedition.svg.SVGMenu;

public class SVGtest extends MIDlet implements CommandListener, SVGEventListener {
public Command iExitCommand;
public Command iContinueCommand;

private SVGMenu svgMenu;
private SVGImage svgImage1;
private Form iForm;

public void startApp() {
iForm = new Form("Title", new Item[] { getString() });
iForm.setCommandListener(this);

iExitCommand = new Command("Exit", Command.EXIT, 0);
iContinueCommand= new Command("Continue", Command.OK, 0);

iForm.addCommand(iExitCommand);
iForm.addCommand(iContinueCommand);

getSvgMenu();
switchDisplayable(null, iForm);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public SVGMenu getSvgMenu() {
if (svgMenu == null) {

svgMenu = new SVGMenu(getSvgImage1(), getDisplay());
svgMenu.setTitle("svgMenu");
svgMenu.addCommand(SVGMenu.SELECT_COMMAND);
svgMenu.setCommandListener(this);
svgMenu.addMenuElement("menuItem_1");
svgMenu.addMenuElement("menuItem_2");
svgMenu.addMenuElement("menuItem_3");
}
return svgMenu;
}

public Display getDisplay() {
return Display.getDisplay(this);
}

public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
Display display = getDisplay();
if (alert == null) {
display.setCurrent(nextDisplayable);
} else {
display.setCurrent(alert, nextDisplayable);
}
}

public SVGImage getSvgImage1() {
if (svgImage1 == null) {
try {
svgImage1 = (SVGImage) SVGImage.createImage(getClass().getResourceAsStream("/menu.svg"), null);
} catch (java.io.IOException e) {
e.printStackTrace();
}
}
return svgImage1;
}

private StringItem getString(){
return new StringItem("PLEASE READ...", "hello world");
}

public void commandAction(Command pCommand, Displayable pDisplayable) {
if(pDisplayable ==iForm)
{
if (pCommand == iExitCommand) {
// write pre-action user code here
exitMIDlet();
// write post-action user code here
} else if (pCommand == iContinueCommand) {
switchDisplayable(null,svgMenu.getSvgCanvas());
}
}
else if (pDisplayable ==svgMenu)
{
switchDisplayable(null,iForm);

int state = svgMenu.getAnimatorState();
try
{
svgMenu.stop();
}catch(Exception E)
{
String mesg = E.getMessage();
E.printStackTrace();
}
svgMenu = null;
}
}

private void exitMIDlet() {
// this is just hard coded until the setting UI is implemented, that should save this setting
destroyApp(true);
notifyDestroyed();
}

public void keyPressed(int arg0) {
}

public void keyReleased(int arg0) {
}

public void pointerPressed(int arg0, int arg1) {
}

public void pointerReleased(int arg0, int arg1) {
}

public void hideNotify() {
}

public void showNotify() {
}

public void sizeChanged(int arg0, int arg1) {
}
}



// the SVG image name is menu.svg & should live in the default package, I borrowed this out of the SVGProject example I found (I have posted this on the sun site)
http://forum.java.sun.com/thread.jsp...38362#10338362