0

UploadEvent media release memory

asked 2015-02-27 12:48:28 +0800

gds1987 gravatar image gds1987
18

Hi all, I have used UploadEvent of ZK to upload huge files like the below codes:

    @Listen("onUpload = #fileupload")
public void updata(UploadEvent evt) {

    log.info("===start to upload");
    Media media = evt.getMedia();
    if(media == null) {
        return;
    }
    log.info("file upload path === " + savePath);
    mediaName = media.getName();
    log.info("media.name() 1 === " + mediaName);        
    long mediaSize = media.getByteData().length;
    log.info("media length === " + mediaSize);

Infact, the codes is simple and it always works well, but what my question is :

How to release the memory which media occupies ?

Even, I write this media into file on DISK, it doesn't work. The memory of my web is huge either.

         if(media.isBinary()) {
        try {
            InputStream input = media.getStreamData();
            FileOutputStream outputStream = new FileOutputStream(savePath);  
            byte[] buf = new byte[1024 * 500];
            int length = 0;  
            while ((length = input.read(buf)) != -1) {
                outputStream.write(buf, 0, length);
            }  

            input.close();
            input = null;
            outputStream.flush();
            outputStream.close();

            showNotify("Upload Success", win);      


          } catch (IOException e1) {
              log.error(e1.getMessage());
              log.error("Upload Error"); 
              System.exit(-1);
          }            
    }

So, are there some methods to release the precious memory that media occupies after it has been written into file on disk ?

Thank you very much!

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-02-27 16:19:02 +0800

chillworld gravatar image chillworld flag of Belgium
5367 4 9
https://github.com/chillw...

Maybe try to close the InputStream and FileOutputStream correct, as in the finally method of the try catch or use try with resources available from Java 1.7.

They both implement the AutoCloseable interface.

Then it should be the garbage collector who needs to take it and dispose it.

Greetz chill.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2015-02-27 12:48:28 +0800

Seen: 12 times

Last updated: Feb 27 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More