OutOfMemory... leak somewhere in this class

I've been programming Java for a few months, and have for the past few weeks been working on this Swing GUI RPG. I know that the below code could be optimised a certain amount by doing lots of things I don't understand but for now all I'm looking for is a memory leak which is causing this to crash after a few minutes of wandering the map.
class GamePanel extends JPanel implements Runnable, KeyListener
    MediaTracker gameStartTracker = new MediaTracker (this);
    MediaTracker gameRunTracker = new MediaTracker (this);
    Toolkit toolkit = Toolkit.getDefaultToolkit ();
    Image worldMap;
    Image mapOnScreen;
    Image worldMapMask;
    int pixels [];
    Player PC = Global.PC;
    Thread GameThread;
    Timer runTimer;
    boolean hasMoved = true; // Cuts out some of the processor usage.
    public GamePanel ()
     PC.reset(0);
        addKeyListener (this);
     GameThread = new Thread (this);
     // Loads GIF's
     try
            worldMap = toolkit.getImage (getClass().getResource("wmap.gif"));
            worldMapMask = toolkit.getImage (getClass().getResource("wmask.gif"));
        catch(Exception ex)
            System.err.println("Could not load world map or it's mask");
     gameStartTracker.addImage (worldMap, 0);
     gameStartTracker.addImage (worldMapMask, 1);
     try
         gameStartTracker.waitForAll();
     catch (InterruptedException ex)
         System.out.println ("Can not process Game Image");
     // Grabs all of the the pixels from the mask
     pixels = new int [worldMapMask.getWidth (this) * worldMapMask.getHeight (this)];
     PixelGrabber pg = new PixelGrabber (worldMapMask, 0, 0, worldMapMask.getWidth (this), worldMapMask.getHeight (this), pixels, 0, worldMapMask.getWidth (this));
     try
         pg.grabPixels ();
     catch (InterruptedException ex)
         System.out.println ("Internal difficulty");
        worldMap.flush();
        worldMapMask.flush();
     runWork ();
    public boolean isFocusTraversable ()
     return true;
    public void paintComponent(Graphics g)
        super.paintComponent(g);
     g.drawImage (mapOnScreen, 1, 1, this);
     g.drawImage (PC.mapIcon, 320, 240, this);
        mapOnScreen.flush();
    public void runWork ()
     if (hasMoved)
         mapOnScreen = createImage (new FilteredImageSource (worldMap.getSource (), new CropImageFilter (PC.x - 320, PC.y - 240, 639, 479)));
            try
                PC.mapIcon = toolkit.getImage (getClass().getResource(PC.mapPicURL));
            catch(Exception ex)
                System.err.println("Could not load character icon!");
         gameRunTracker.addImage (mapOnScreen, 0);
         gameRunTracker.addImage (PC.mapIcon, 1);
         try
          gameRunTracker.waitForAll ();
         catch (InterruptedException ex)
          System.err.println ("Can not process image");
            repaint();
         hasMoved = false;
    public void run ()
     while (true)
         runWork ();
    public void startGame ()
     hasMoved = true;
     GameThread.start();
    public void keyPressed (java.awt.event.KeyEvent keyEvent)
     hasMoved = true;
     if (keyEvent.getKeyCode () == KeyEvent.VK_RIGHT)
         int pixel = pixels [PC.y * worldMapMask.getWidth (this) + (PC.x + PC.mapIcon.getWidth (this) + PC.speed)];
         int red = (pixel >> 16) & 0xff;
         int green = (pixel >> 8) & 0xff;
         int blue = (pixel) & 0xff;
         if (red != 0 && green != 0 && blue != 0)
          PC.mapPicURL = "pcr0.gif";
          PC.x = PC.x + PC.speed;
     else if (keyEvent.getKeyCode () == KeyEvent.VK_LEFT)
         int pixel = pixels [PC.y * worldMapMask.getWidth (this) + (PC.x - PC.speed)];
         int red = (pixel >> 16) & 0xff;
         int green = (pixel >> 8) & 0xff;
         int blue = (pixel) & 0xff;
         if (red != 0 && green != 0 && blue != 0)
          PC.mapPicURL = "pcl2.gif";
          PC.x = PC.x - PC.speed;
     else if (keyEvent.getKeyCode () == KeyEvent.VK_DOWN)
         int pixel = pixels [(PC.y + PC.mapIcon.getHeight (this) + PC.speed) * worldMapMask.getWidth (this) + PC.x];
         int red = (pixel >> 16) & 0xff;
         int green = (pixel >> 8) & 0xff;
         int blue = (pixel) & 0xff;
         if (red != 0 && green != 0 && blue != 0)
          PC.mapPicURL = "pcd0.gif";
          PC.y = PC.y + PC.speed;
     else if (keyEvent.getKeyCode () == KeyEvent.VK_UP)
         int pixel = pixels [(PC.y - PC.speed) * worldMapMask.getWidth (this) + PC.x];
         int red = (pixel >> 16) & 0xff;
         int green = (pixel >> 8) & 0xff;
         int blue = (pixel) & 0xff;
         if (red != 0 && green != 0 && blue != 0)
          PC.mapPicURL = "pcu0.gif";
          PC.y = PC.y - PC.speed;
     else
    public void keyReleased (java.awt.event.KeyEvent keyEvent)
    public void keyTyped (java.awt.event.KeyEvent keyEvent)

Hello,
I am not sure if this will fix your problem but here goes,
First off run your application through a profiler it may well give you some clues as to where the problem lies.
Have you tried increasing the heap memory allocated to your JVM, it may be that you just need more memory than you exapectd
e.g java -Xms64m -Xmx64m sets the minimum and maximum heap sixe to 64mb.
Also it looks like you may be creating a lot of objects in your code, (extensive use of the new operator) maybe you can try using an object pool, this will not only help manage your memnory problems but will also improve the performance of your application because object creation is a relativley time expensive task, using object pools you can create all the objects you want as our app initialises, slower starup time but improved running performance.

Similar Messages

  • [JS, CS4] TextFrame.extractLabel() cannot work with instances of this class

    I have script, which has been working fine in CS3. In CS4 ( app.version = 6.0.1.532 ) however, I get an error using extractLabel, after reading out a couple of other properties from a textframe:
    frameObject.extractLabel('name')
    Error: TextFrame.extractLabel() cannot work with instances of this class
    Up until reading one of the "normal" properties, such as (frameObject.)contents I can call the frameObject.extractLabel('name') without errors, but after "looking at" (by assigning to a variable in code, or by getting the value in the javascript console), the contents propery (or as it seems any normal property) the extractLabel method results in the error above.
    It seems to work to move all of the frameObject.extractLabel calls to the beginning of the function, but I don't think I should need to do that.
    It might very well be the case that the label read by extractLabel has no contents, and has never been assigned. Is there a change in behaviour from CS3 in that sentence? If so, and if thats the reason for the error, is there then a way to determine whether the label has ever been assigned?
    Is this error familiar to anyone else?
    Best regards,
    Andreas

    Hi Andreas,
    Interesting problem!
    Your problems are caused by some peculiarities of itemByID. itemByID doesn't cast the object type properly. Dirk wrote about some aspects of this some time ago. If the scripting engine was strongly typed, this issue would probably be impossible but that would make scripting a lot more of an elitist activity!
    Your problem is that the object type is PageItem and you are accessing a TextFrame property (content). This seems to throw the object type for a loop.
    Using getElements() causes the scripting engine to rebuild the reference to the object correctly.
    Take a look at this code, which illustrates the issue quite well...
    var myDocument = app.documents.add();
    myDocument = app.activeDocument;
    myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
    myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
    var myTextFrame = myDocument.pages.item(0).textFrames.add({geometricBounds:[72, 72, 144, 288], contents:"test"});
    var myId = myTextFrame.id;
    var pgItm = myDocument.pageItems.itemByID(myId);
    alert(pgItm instanceof PageItem);
    alert(pgItm instanceof TextFrame);
    var thisBounds = pgItm.geometricBounds;
    var x = pgItm.extractLabel('mandatory');
    var pgItm = myDocument.textFrames.itemByID(myId);
    alert(pgItm instanceof PageItem);
    alert(pgItm instanceof TextFrame);
    var thisName = pgItm.extractLabel('name');
    var thisContents = pgItm.contents;
    var x = pgItm.extractLabel('mandatory');
    Harbs

  • Web Deploy error - "This method is not supported by this class"

    I have an MVC project which I am trying to deploy to one of our internally-hosted web front end servers via a TFS build process. Our server hosts the MS Deploy service, and other solutions deploy without problems to the same box. The parameters for the build
    process are as follows:
    /p:DeployOnBuild=True /p:DeployTarget=MsDeployPublish /p:MSDeployPublishMethod=WMSVC /p:MsDeployServiceUrl=https://<server>:8172/msdeploy.axd /p:DeployIISAppPath="<internal.site.com>" /p:username=<username> /p:password=<password>
    /p:IncludeIisSettingsOnPublish=false /p:AllowUntrustedCertificate=True /p:OutputPath=bin\ /p:SkipExtraFilesOnServer=True /p:VisualStudioVersion=11.0
    The error message I receive at the point the build reaches the deployment activity is:
    Web deployment task failed. (Could not complete the request to remote agent URL 'https://<server>:8172/msdeploy.axd?site=<internal.site.com>'.)
    Could not complete the request to remote agent URL 'https://<server>:8172/msdeploy.axd?site=<internal.site.com>'.
    The request was aborted: The request was canceled.
    This method is not supported by this class.
    We've found
    this StackOverflow post which describes the same error we're experiencing, however the suggested solution is something we already do in our server configuration, so this doesn't resolve the issue for us.
    Has anyone seen this error before, or is able to make any suggestions why it is happening?

    Hi Matt,
    You have to have a look in the build log then copy the command that is under Run MSBuild node and executed it on the build agent.
    You should find something like below:
    C:\Program Files (x86)\MSBuild\12.0\bin\amd64\MSBuild.exe /nologo /noconsolelogger "C:\Builds\....sln" /nr:False /fl /flp:"logfile=C:\Builds\...log;encoding=Unicode;verbosity=normal" /p:SkipInvalidConfigurations=true /p:CreatePackageOnPublish=true /p:DeployOnBuild=true /p:SkipExtraFilesOnServer=True /m /p:OutDir="C:\Builds\...\bin\\" /p:Configuration="DEV" /p:Platform="Any CPU" /p:VCBuildOverride="C:\Builds\....sln.Any CPU.DEV.vsprops" /dl:WorkflowCentralLogger,"C:\Program Files\Microsoft Team Foundation Server 12.0\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;BuildUri=vstfs:///Build/Build/31630;IgnoreDuplicateProjects=False;InformationNodeId=14;TargetsNotLogged=GetNativeManifest,GetCopyToOutputDirectoryItems,GetTargetPath;LogProjectNodes=True;LogWarnings=True;TFSUrl=http://...-tfs:8080/tfs/...;"*WorkflowForwardingLogger,"C:\Program Files\Microsoft Team Foundation Server 12.0\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;" /p:BuildId="aa2d3857-27e9-4854-b44f-4ca625ccd786,vstfs:///Build/Build/31630" /p:BuildLabel="..._2015.02.27.2" /p:BuildTimestamp="Fri, 27 Feb 2015 11:16:41 GMT" /p:BuildDefinition="..."
    Daniel

  • In wich jar can i get this class org.apache.batik.dom.util.DOMUtilities

    please let me know in which jar file can i get this class and tell me the location for downloading
    org.apache.batik.dom.util.DOMUtilities;
    import org.w3c.dom.Document;

    Hai,
    I think you have to use the xml-apis.jar file from the batik project, which has the class org.apache.batik.dom.util.DOMUtilities.
    Yogesh.

  • When i executed this class file  i am getting runtime errors

    when i executed this class file i am getting runtime errors
    code is :
    import java.awt.event.*;
    import java.awt.*;
    public class Test extends Frame
    java.awt.Window w;
         TextField t;
         Test()
         t=new TextField(20);
         add(t);
         addWindowListener(new WindowAdapter()
                             public void windowDeactivated(WindowEvent ev)                               {                    
                                  w.toFront();          
                                  System.out.println("hai");
         setSize(300,300);
         setVisible(true);
    public static void main(String args[])
    Test t =new Test();
    after executing that class i am getting this errors
    Exception occurred during event dispatching:
    java.lang.NullPointerException:
    at WindowEventDemo.windowActivated(WindowEventDemo.java:76)
    at java.awt.Window.processWindowEvent(Window.java:612)
    at java.awt.Window.processEvent(Window.java:576)
    at java.awt.Component.dispatchEventImpl(Compiled Code)
    at java.awt.Container.dispatchEventImpl(Compiled Code)
    at java.awt.Window.dispatchEventImpl(Compiled Code)
    at java.awt.Component.dispatchEvent(Compiled Code)
    at java.awt.EventQueue.dispatchEvent(Compiled Code)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:68)
    if anybody know how to pls help me

    You are using w that you have not done anything with.
    Add following code to the begining of your cinstructor:
    w = this;
    Then it should work.
    //Anders ;-D

  • Need help making this class Runnable.

    Hello,
    This class (see below) is working fine the way it is but I have a little problem, I need to execute aprox 500+ commands and each command takes between 30sec to 3 minutes to complete which translate into hours for the job to finish.
    I want to speed the process by multi-tasking and executing (possibly) all commands simultaniously by somehow making this class Threaded/Runnable (miltitasking). There must be something tricky about Runtime class and cannot figured it out.
    Your help would be highly appreciated.
    Regards,
    Ulises
    public class CmdTest {     
    public static void main(String[] args) throws java.io.IOException {
    String outFile = "./ds8300/lsvogrp.txt";
    PrintWriter bout = null;
    try {
    bout     = new PrintWriter(                         new FileWriter(new File(outFile)));     
    } catch (IOException e) {
         e.printStackTrace();
    Runtime run = Runtime.getRuntime();
    run.traceMethodCalls(true);
    Process proc2 = run.exec("cmd /c dscli -user user -passwd psw" + "lsvolgrp -l");
    BufferedWriter ot = new BufferedWriter(
    new OutputStreamWriter(proc2.getOutputStream()));
    BufferedReader br = new BufferedReader(
    new InputStreamReader(proc2.getInputStream()));
    BufferedReader er = new BufferedReader(
    new InputStreamReader(proc2.getErrorStream()));
    try {
    String s;
    while((s=br.readLine())!=null) {
         System.out.println(""+s);
         bout.println(s);
    while((s=er.readLine())!=null) System.out.println("ERR:"+s);
    bout.close();
    System.exit(0);
    }catch (Exception ie) { //catch (InterruptedException ie) {
    System.out.println("Interrupted:"+ie.getMessage());}
    }

    Seems like the same question you asked last year.
    http://forum.java.sun.com/thread.jspa?threadID=5181153&messageID=9705196#9705196
    The proper way to design software is to start at the beginning and design Classes. Not try to butcher that which is working.
    You're running work outside the JVM and this work might interfere with other, similar work (the multi-threading issue.)
    I'd start with paper and pencil and see what conflicts might arise.

  • Is this class available CL_GUI_WDR_VIEWER? Urgent Solution Needed.

    Hi Experts,
    Please check the blog below.
    /people/david.fernandespietroniro/blog/2008/06/19/web-dynpro-running-web-dynpro-applications-over-sapgui
    In this blog he used CL_GUI_WDR_VIEWER to declare lr_viewer.
    But when i tried this blog, i'm not able to locate this class.
    I checked SE24. there is no class in this name.
    My question is : Is there any other class available like CL_GUI_WDR_VIEWER.(To do the same blog).
    Expecting Reply ASAP
    Thanks & Regards
    SM Nizamudeen

    Hello Nizamudeen,
    This class was released with the version 700 of SAP_BASIS component. I'm writing a new blog that shows how to call web dynpros in later versions, but for while take a look at the program RSDEMO_HTML_VIEWER.
    Regards.

  • [svn:bz-trunk] 21285: Need to change _parent, privateCall and instance properties from private to protected in order to extend this class for another project

    Revision: 21285
    Revision: 21285
    Author:   [email protected]
    Date:     2011-05-20 07:53:23 -0700 (Fri, 20 May 2011)
    Log Message:
    Need to change _parent, privateCall and instance properties from private to protected in order to extend this class for another project
    Modified Paths:
        blazeds/trunk/apps/ds-console/console/ConsoleManager.as

    Revision: 21285
    Revision: 21285
    Author:   [email protected]
    Date:     2011-05-20 07:53:23 -0700 (Fri, 20 May 2011)
    Log Message:
    Need to change _parent, privateCall and instance properties from private to protected in order to extend this class for another project
    Modified Paths:
        blazeds/trunk/apps/ds-console/console/ConsoleManager.as

  • I created a class file , if i execute this class file it has to be always o

    i created a class file , if i execute this class file it has to be always on top if i open any other programms or applications then also this class file application has to show me on the screen top , i meas ti has to show me first and behind all applications which i opend other applications
    How to do this please help me
    bhaskar

    It sounds like you might be able to write a .bat script to run the application, create a desktop icon for that and set its properties so it runs in the background.

  • JApplet calls a Class. This Class needs Input

    I am doing something in a JApplet. After the user click in a jButton called Execute, this JApplet use a class (Processing) to process some inputs which comes meanwhile this class (Processing) is running. I need some input from the user but not in the way of JOptionPane. I would like to show some more elegant dialog with checkboxes and buttons. How can I do this? Thx for help me!

    I am doing something in a JApplet. After the user click in a jButton called Execute, this JApplet use a class (Processing) to process some inputs which comes meanwhile this class (Processing) is running. I need some input from the user but not in the way of JOptionPane. I would like to show some more elegant dialog with checkboxes and buttons. How can I do this? Thx for help me!

  • "cannot find this class" erro while creating Background Callable Object.

    Hi All,
    I am facing "cannot find this class" while creating Background Callable Object.
    I followed the following document for Creating Background Callable Object.
    [Creating Callable Objects for Background Execution|http://help.sap.com/saphelp_nwce10/helpdata/en/53/cde385301f4aa3b8e77a92cd46bff3/frameset.htm]
    After giving the fully qualified java class name in the Implementation Class Name when i press next i am getting the error.
    Please suggets me in solving this issue.
    Regards,
    S.V.Satish Kumar
    Edited by: Sathish Kumar SV on Apr 4, 2009 10:34 AM

    Hi, kavita.
    First, make sure you choosed the correct container when you created the background CO.
    Second, make sure your package name was "com.examples.bckgco" and class name was "UserDetailsCallableObject". The exception  which you got just means you entered incorrect name.
    It doesn`t relate to your program.
    Best Regards.
    Louis Huang.

  • What does the class CL_EXITHANDLER do ? What the significance of this class

    what does the class CL_EXITHANDLER do ? What the significance of this class,

    Peters,
    Welcome to SDN!
    you can see this class in SE24 and than choose GET INSTENCE method DB on it. than put break-point on
    CALL METHODcl_exithandler=>get_class_name_by_interface
    finally run any t-code you will come into debugger mode and if you see in exit_name value after pressing F6 you will get BADi name of this perticuler T-code.
    basically we use this class for findings BADi.
    Amit.

  • Why can't I use this class inside my MovieClip?

    Hi,
    The attached SlideshowExample.as file works quite nice when I use it on stage directly. But when I tried to use it in Gallery_mc movie clip, it doesn't work, Please help me out in resolving this problem.
    Sorry, I think there is no file attachment option here.
    Thanks.

    What you need to do is to attach this class "SlideshowExample" to your MovieClip symbol in the Library, then instantiate it and add it to the display list. (If you want to use the name "Gallery_mc" then you can rename the class to 'Gallery_mc".)
    Kenneth Kawamoto
    http://www.materiaprima.co.uk/

  • How do I create an genericized instance of this class?

    Hi, I'm having trouble creating a proper generic instance of this class that I wrote. The class type is cyclic dependant on itself.
    public class MyClass<T extends MyClass<T>>
    I can create an instance like this:
    MyClass<?> class = new MyClass();But I would be mixing raw types and generic types.
    Is there anyway to create a proper generic instance of MyClass?
    Thanks a lot
    -Cuppo

    Ah thanks georgemc,
    your solution will certainly work.
    If i may ask your opinion of something...
    MyClass is designed such that the type parameter should always be the same as the class itself. It's kinda a hack to get the subclass type from the superclass.
    so a hierarchy looks something like this:
    class MyClass<T extends MyClass<T> >
    class SubClass<T extends SubClass<T>> extends MyClass<T>
    class FinalSubClass extends SubClass<FinalSubClass>So ideally i would want something like:
    MyClass m = new MyClass<MyClass>();
    (which is not possible)
    is there a way to get around this?
    -Cuppo

  • What is the name of this class?

    I have a JTable which is instantiated like this:
    "class table2 extends JTable {
         private int rows = 100, cols = 8;
         private Object[] rowData = new Object[cols];
    When I try to refer to it as "table2," I get a null pointer exception.
    My questions:
    What is the name of that class?
    Is there a way to reference it as "table2"?
    Many thanks in advance.

    Hello
    I might have the answer to your problem but firstly, is that all the code there is? For example, where is the constructor for your class?
    In answer to your questions:
    1. You cannot reference an object until it has been created (this might explain the NullPointerException)
    2. To reference it as "table2" you would do something like this:
    table2 table2 = new table2();Looks a bit confusing... :(
    You should start class names with capital letters and also choose a general name for the class like this:
    MyTable table2 = new MyTable();
    MyTable table3 = new MyTable();and so on.
    Post another message if you need more help.
    Regards
    Daniel Lam

Maybe you are looking for

  • In XML field is missed

    Hi All, I have query related field mapping. My field mapping is working in Development server but same mapping is not working in QA. In QA i can see all mapping. During IDOC generation in one field record is coming, but in XML particular field is not

  • InternalCatalogException in Reporting Services 2008 - no reports rendering

    Hi all, We've had an unexpected outage on two of our reporting services server overnight and we're hoping someone can point us in the right direction.  We have a Windows Server 2008 machine running about 5 instances of reporting services in standalon

  • Error in Weblogic Deployment

    java.lang.reflect.UndeclaredThrowableException: weblogic.j2ee.DeploymentException: Could not load web application from '..\..\project\wlproj\defaultroot' I dont know if this is the right forum to ask this question. Anyways. I am using JBuilder Enterp

  • System Preferences crashes

    System Preferences crashes everytime I click on "Security", "Keyboard & Mouse", and "Sound". I got a Mighty Mouse for Christmas, and I need to change the settings of it. Everytime I click on "Keyboard & Mouse" it crashes. Can anybody help me? Thanks!

  • Can i put a MDD/FW800 processor in an AGP Powermac G4?

    topic question says it all? is this possible?