OutOfMemoryError

Discussion in 'Java' started by Marcelo, Nov 7, 2005.

  1. Marcelo

    Marcelo Guest

    Dear programmers,

    I am having the following message whenever I do a massive retrieve of
    images.

    The program has some threads that saves an images from the internet to
    my hard-disk, however, because I don't know the size of these images, I
    have put
    int MAX_IMAGE_SIZE = 5000000;

    for the buffer.

    And obviously I get the error-message

    Exception in thread "Thread-17" java.lang.OutOfMemoryError: Java heap space

    How can i know the Size of my image before downloading it ? Is it
    possible to give a maximum size of 5Mpix without having this problem?

    thank you for your advises,

    Marcelo
     
    Marcelo, Nov 7, 2005
    #1
    1. Advertising

  2. Marcelo

    Ben_ Guest

    You download them with an HTTP request, I suppose ?

    You can get the size with URLConnection.getContentLength (or similar --
    depends on the API you use), if the server bothered specifying the length.

    Anyway, you can read it and write it progressively in small chunks. You
    need not necessarily keep all the image in a single large buffer in memory,
    especially, when you simply have to save the file to disk.
     
    Ben_, Nov 7, 2005
    #2
    1. Advertising

  3. Marcelo

    Roedy Green Guest

    On Mon, 07 Nov 2005 23:05:22 +0100, Marcelo <> wrote,
    quoted or indirectly quoted someone who said :

    >How can i know the Size of my image before downloading it ? Is it
    >possible to give a maximum size of 5Mpix without having this problem?


    There is an http header request that will often tell you the length,
    date etc.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Nov 8, 2005
    #3
  4. Marcelo

    Roedy Green Guest

    On Mon, 07 Nov 2005 23:05:22 +0100, Marcelo <> wrote,
    quoted or indirectly quoted someone who said :

    >The program has some threads that saves an images from the internet to
    >my hard-disk, however, because I don't know the size of these images, I
    >have put
    >int MAX_IMAGE_SIZE = 5000000;
    >
    >for the buffer.


    see http://mindprod.com/products1.html#FILETRANSFER

    it downloads in chunks.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Nov 8, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGF2ZQ==?=

    Serialize session state & OutOfMemoryError?

    =?Utf-8?B?RGF2ZQ==?=, Sep 8, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,565
    =?Utf-8?B?RGF2ZQ==?=
    Sep 8, 2005
  2. Robert Olofsson
    Replies:
    3
    Views:
    3,032
    Sunitha Kumar
    Jul 3, 2003
  3. Ian Suttle
    Replies:
    2
    Views:
    2,347
    Wolfram Rittmeyer
    Aug 27, 2003
  4. Dean
    Replies:
    1
    Views:
    656
    Robert Olofsson
    Sep 8, 2003
  5. Xiaopeng Xiong

    java.lang.OutOfMemoryError problem

    Xiaopeng Xiong, Nov 14, 2003, in forum: Java
    Replies:
    3
    Views:
    449
    Xiaopeng Xiong
    Nov 15, 2003
Loading...

Share This Page