You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Giovanni <va...@gmail.com> on 2013/08/31 18:27:26 UTC
"OutOfMemoryError: Java heap space" when i try to upload and show a
hundred 100kb pics
Hi!
I need to display more than a hundred pictures on the page (about 100kb -
300kb), i but I got the error about heap. I read that the reason of this
error could be serialization of the page, but I don't know, how to solve
this.
TestMultipleImages.html:
/<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns:wicket="http://wicket.apache.org">
<head>
</head>
<body>
<form wicket:id="form">
<input wicket:id="uploadField" type="file" multiple />
<button>SUMBIT</button>
</form>
</body>
</html>/
TestMultipleImages.java:
/public class TestMultipleImages extends WebPage {
private FileUploadField uploadField;
private Form<String> form;
private static List<BufferedImage> images = new ArrayList<BufferedImage>();
@Override
protected void onBeforeRender() {
removeAll();
RepeatingView imageRepeater = new RepeatingView("imageRepeater");
add(imageRepeater);
for (BufferedImage image : images) {
WebMarkupContainer container = new
WebMarkupContainer(imageRepeater.newChildId());
imageRepeater.add(container);
BufferedDynamicImageResource resource = new
BufferedDynamicImageResource();
resource.setImage(image);
container.add(new Image("image", resource));
}
form = new Form<String>("form") {
@Override
protected void onSubmit() {
for (FileUpload fileUpload : uploadField.getModelObject()) {
byte[] bytes = fileUpload.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
BufferedImage readedImage = null;
try {
readedImage = ImageIO.read(bais);
bais.close();
} catch (IOException e) {
e.printStackTrace();
}
images.add(readedImage);
}
super.onSubmit();
}
};
uploadField = new FileUploadField("uploadField");
uploadField.setModel(new ListModel<FileUpload>());
form.add(uploadField);
add(form);
super.onBeforeRender();
}
}/
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/OutOfMemoryError-Java-heap-space-when-i-try-to-upload-and-show-a-hundred-100kb-pics-tp4661159.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: "OutOfMemoryError: Java heap space" when i try to upload and show
a hundred 100kb pics
Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Try memory profiler to see what is at matter.
**
Martin
2013/9/1 Giovanni <va...@gmail.com>
> Martin Grigorov-4 wrote
> > Hi,
> > Read about Java memory settings (-Xms, -Xmx)
>
> Yes, I can increase heap space by settings, but is this a good approach? If
> displaying one 10Mb pic consumes 1.5Gb heap space - is this normal? Maybe
> there are other ways to solve this problem without increasing heap space by
> settings?
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/OutOfMemoryError-Java-heap-space-when-i-try-to-upload-and-show-a-hundred-100kb-pics-tp4661159p4661161.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: "OutOfMemoryError: Java heap space" when i try to upload and
show a hundred 100kb pics
Posted by Michael Mosmann <mi...@mosmann.de>.
Am 01.09.13 10:53, schrieb Giovanni:
> Martin Grigorov-4 wrote
>> Hi,
>> Read about Java memory settings (-Xms, -Xmx)
> Yes, I can increase heap space by settings, but is this a good approach? If
> displaying one 10Mb pic consumes 1.5Gb heap space - is this normal? Maybe
> there are other ways to solve this problem without increasing heap space by
> settings?
I think there is a better solution if you do not have unlimited memory
:). See http://wicketinaction.com/2011/07/wicket-1-5-mounting-resources/
. You generate every image in your page render loop. This way the image
data is stored in your page (which is bad). If you use a
DynamichImageResource the image is created when the image request comes
in. But you have to store your images somewhere else (remove this static
list of buffered images) and refer to them with an ID.
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: "OutOfMemoryError: Java heap space" when i try to upload and
show a hundred 100kb pics
Posted by Giovanni <va...@gmail.com>.
Martin Grigorov-4 wrote
> Hi,
> Read about Java memory settings (-Xms, -Xmx)
Yes, I can increase heap space by settings, but is this a good approach? If
displaying one 10Mb pic consumes 1.5Gb heap space - is this normal? Maybe
there are other ways to solve this problem without increasing heap space by
settings?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/OutOfMemoryError-Java-heap-space-when-i-try-to-upload-and-show-a-hundred-100kb-pics-tp4661159p4661161.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: "OutOfMemoryError: Java heap space" when i try to upload and show
a hundred 100kb pics
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
On Sat, Aug 31, 2013 at 7:27 PM, Giovanni <va...@gmail.com> wrote:
> Hi!
> I need to display more than a hundred pictures on the page (about 100kb -
> 300kb), i but I got the error about heap. I read that the reason of this
> error could be serialization of the page, but I don't know, how to solve
> this.
>
Read about Java memory settings (-Xms, -Xmx)
>
> TestMultipleImages.html:
> /<?xml version="1.0" encoding="UTF-8" ?>
> <html xmlns:wicket="http://wicket.apache.org">
> <head>
> </head>
> <body>
>
> <form wicket:id="form">
> <input wicket:id="uploadField" type="file" multiple />
> <button>SUMBIT</button>
> </form>
>
>
>
>
> </body>
> </html>/
>
> TestMultipleImages.java:
> /public class TestMultipleImages extends WebPage {
> private FileUploadField uploadField;
> private Form<String> form;
>
> private static List<BufferedImage> images = new
> ArrayList<BufferedImage>();
>
> @Override
> protected void onBeforeRender() {
> removeAll();
>
> RepeatingView imageRepeater = new
> RepeatingView("imageRepeater");
> add(imageRepeater);
> for (BufferedImage image : images) {
> WebMarkupContainer container = new
> WebMarkupContainer(imageRepeater.newChildId());
> imageRepeater.add(container);
>
> BufferedDynamicImageResource resource = new
> BufferedDynamicImageResource();
> resource.setImage(image);
>
> container.add(new Image("image", resource));
> }
>
> form = new Form<String>("form") {
> @Override
> protected void onSubmit() {
> for (FileUpload fileUpload :
> uploadField.getModelObject()) {
> byte[] bytes =
> fileUpload.getBytes();
>
> ByteArrayInputStream bais = new
> ByteArrayInputStream(bytes);
> BufferedImage readedImage = null;
> try {
> readedImage =
> ImageIO.read(bais);
> bais.close();
> } catch (IOException e) {
> e.printStackTrace();
> }
> images.add(readedImage);
> }
>
> super.onSubmit();
> }
> };
>
> uploadField = new FileUploadField("uploadField");
> uploadField.setModel(new ListModel<FileUpload>());
> form.add(uploadField);
> add(form);
>
> super.onBeforeRender();
> }
> }/
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/OutOfMemoryError-Java-heap-space-when-i-try-to-upload-and-show-a-hundred-100kb-pics-tp4661159.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>