内存不足运行的时候java -Xmx256M (youclassname)

解决方案 »

  1.   

    程序的工作是:
    服务器:接收客户端发来的image对象(也就是图片)客户端:先截取屏幕,将它转化为image类型,发发送到服务器端。在运行了一会儿后就出现了out of memories的错误不知道怎么解决,请指点一下。
      

  2.   

    我觉得好像不是内存不足的问题,而是我的程序占了内存没有释放而引起。
    因为,刚开始时是可以运行,但是过了半分钟后,就出现了out of memories的错误,程序终止了。请再来指点一下!
      

  3.   

    while (true) {
                    bi=robot.createScreenCapture(new Rectangle(800,600));//?????
                    System.out.println("create Screen Capture is ok!");
                    
                    image=new ImageIcon((Image)bi);
                    out.writeObject(image);
                    out.flush();
                    out.close();
                    image=null;
                    try {
                        Thread.sleep(1500); 
                    }
                    catch (Exception ex) {
                        System.err.println("sleep error.");
                    }            
                }
      

  4.   

    如上所述,socket流应该在使用完后关闭。如你的out,is
      

  5.   

    简单写了一下,SOCKET连接部分没有写。
        public void send() {
            try {
                File f = new File("d:\\test.jpg");
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
                BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
                int ch = bis.read();
                while(ch != -1) {
                    bos.write(ch);
                    ch = bis.read();
                }
                bos.flush();
                bos.close();
                bis.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }    public void receive() {
            try {
                File f = new File("d:\\test1.jpg");
                if(!f.exists()) {
                    f.createNewFile();
                }
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f));
                BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
                int ch = bis.read();
                while(ch != -1) {
                    bos.write(ch);
                    ch = bis.read();
                }
                bos.flush();
                bos.close();
                bis.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
      

  6.   

    我想要ObjectOutputStream,看来我还是自己搞吧。