B4J Question Java heap space

Tayfur

Well-Known Member
Licensed User
Longtime User
Hello;
My app loading in mylist all pictures.
I trying big sized pictures from lan. (1-2mb). When I loaded 3 pcs , I read some error like under below.
How can fix it.

it s broken line on "initialize."
B4X:
Dim bmp As Image
bmp.Initialize2(File.OpenInput(xDir,xName))

I've tried uploading a lot of pictures. (size 300Kb) but it s not broken.
I've tried uploading 2 PNG pictures. (size 1640Kb) After app broked when I added 3. PNG picture.
all png pictures are same file.

Waiting for debugger to connect...
Program started.
burası kıralabilir
resize gerisi
16:05:34
java.lang.OutOfMemoryError: Java heap space
at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:57)
at java.nio.ByteBuffer.allocate(ByteBuffer.java:335)
at com.sun.javafx.iio.png.PNGImageLoader2.load(PNGImageLoader2.java:652)
at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:364)
at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:274)
at com.sun.javafx.tk.quantum.PrismImageLoader2.loadAll(PrismImageLoader2.java:142)
at com.sun.javafx.tk.quantum.PrismImageLoader2.<init>(PrismImageLoader2.java:77)
at com.sun.javafx.tk.quantum.QuantumToolkit.loadImage(QuantumToolkit.java:732)
at javafx.scene.image.Image.loadImage(Image.java:1073)
at javafx.scene.image.Image.initialize(Image.java:804)
at javafx.scene.image.Image.<init>(Image.java:707)
at anywheresoftware.b4j.objects.ImageViewWrapper$ImageWrapper.Initialize2(ImageViewWrapper.java:129)
at b4j.example.resim._addpicture(resim.java:193)
at b4j.example.main._button1_click(main.java:150)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:628)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA$1.run(BA.java:215)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$49/341111117.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
java.lang.RuntimeException: java.lang.OutOfMemoryError: Java heap space
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA$1.run(BA.java:215)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.OutOfMemoryError: Java heap space
at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:57)
at java.nio.ByteBuffer.allocate(ByteBuffer.java:335)
at com.sun.javafx.iio.png.PNGImageLoader2.load(PNGImageLoader2.java:652)
at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:364)
at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:274)
at com.sun.javafx.tk.quantum.PrismImageLoader2.loadAll(PrismImageLoader2.java:142)
at com.sun.javafx.tk.quantum.PrismImageLoader2.<init>(PrismImageLoader2.java:77)
at com.sun.javafx.tk.quantum.QuantumToolkit.loadImage(QuantumToolkit.java:732)
at javafx.scene.image.Image.loadImage(Image.java:1073)
at javafx.scene.image.Image.initialize(Image.java:804)
at javafx.scene.image.Image.<init>(Image.java:707)
at anywheresoftware.b4j.objects.ImageViewWrapper$ImageWrapper.Initialize2(ImageViewWrapper.java:129)
at b4j.example.resim._addpicture(resim.java:193)
at b4j.example.main._button1_click(main.java:150)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:628)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA$1.run(BA.java:215)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$49/341111117.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
 
Last edited:

Tayfur

Well-Known Member
Licensed User
Longtime User

app is not start/show

B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
    #VirtualMachineArgs :java -Xmx2048m -jar GetImageSize.jar
#End Region


upload_2018-12-7_16-47-17.png
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
That is the command line option, within the ide you just need :
B4X:
#VirtualMachineArgs: -Xmx2048m
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
That is the command line option, within the ide you just need :
B4X:
#VirtualMachineArgs: -Xmx2048m
I tried it. And results is very very interesting. Java burning...

I tested with 30pcs.

upload_2018-12-7_17-23-31.png



Some time disk usage rate 100% :)
CPU rate 75%
after broken code.


Waiting for debugger to connect...
Program started.
17:15:55
1
1 complate
2
2 complate
3
3 complate
4
4 complate
5
5 complate
6
6 complate
7
7 complate
8
8 complate
9
9 complate
java.lang.OutOfMemoryError: Java heap space
at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:57)
at java.nio.ByteBuffer.allocate(ByteBuffer.java:335)
at com.sun.javafx.iio.png.PNGImageLoader2.load(PNGImageLoader2.java:652)
at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:364)
at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:274)
at com.sun.javafx.tk.quantum.PrismImageLoader2.loadAll(PrismImageLoader2.java:142)
at com.sun.javafx.tk.quantum.PrismImageLoader2.<init>(PrismImageLoader2.java:77)
at com.sun.javafx.tk.quantum.QuantumToolkit.loadImage(QuantumToolkit.java:732)
at javafx.scene.image.Image.loadImage(Image.java:1073)
at javafx.scene.image.Image.initialize(Image.java:804)
at javafx.scene.image.Image.<init>(Image.java:707)
at anywheresoftware.b4j.objects.ImageViewWrapper$ImageWrapper.Initialize2(ImageViewWrapper.java:129)
at b4j.example.resim._addpicture(resim.java:249)
at b4j.example.main._button1_click(main.java:152)
10
10 complate
11
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:628)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA$1.run(BA.java:215)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$49/2106353043.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
java.lang.RuntimeException: java.lang.OutOfMemoryError: Java heap space
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA$1.run(BA.java:215)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.OutOfMemoryError: Java heap space
at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:57)
at java.nio.ByteBuffer.allocate(ByteBuffer.java:335)
at com.sun.javafx.iio.png.PNGImageLoader2.load(PNGImageLoader2.java:652)
at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:364)
at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:274)
at com.sun.javafx.tk.quantum.PrismImageLoader2.loadAll(PrismImageLoader2.java:142)
at com.sun.javafx.tk.quantum.PrismImageLoader2.<init>(PrismImageLoader2.java:77)
at com.sun.javafx.tk.quantum.QuantumToolkit.loadImage(QuantumToolkit.java:732)
at javafx.scene.image.Image.loadImage(Image.java:1073)
at javafx.scene.image.Image.initialize(Image.java:804)
at javafx.scene.image.Image.<init>(Image.java:707)
at anywheresoftware.b4j.objects.ImageViewWrapper$ImageWrapper.Initialize2(ImageViewWrapper.java:129)
at b4j.example.resim._addpicture(resim.java:249)
at b4j.example.main._button1_click(main.java:152)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:628)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA$1.run(BA.java:215)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$49/2106353043.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If you are loading multiple images, you will have to try managing them. one option would be to download one at a time, save it to disk the loadbitmapSample to display a smaller view of each.
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
If you are loading multiple images, you will have to try managing them. one option would be to download one at a time, save it to disk the loadbitmapSample to display a smaller view of each.


I added sample project ; with out image.

image size : 9933x7016

upload_2018-12-7_17-44-9.png



New
If you are loading multiple images, you will have to try managing them. one option would be to download one at a time, save it to disk the loadbitmapSample to display a smaller view of each.
But i need to learn real image size. Therefore "bmp.Initialize2(File.OpenInput(xDir,xName))"
 

Attachments

  • test2.zip
    16.8 KB · Views: 233
Upvote 0
Top