J
J
John Ashley2016-12-20 18:30:36
Java
John Ashley, 2016-12-20 18:30:36

How to work with threads in swing?

In short, I use swingworker to create a thread in which the neural network is executed. This neural network consumes a lot of RAM. More than a gigabyte. When you click on the "start" button, the name of the button changes to "stop", a neural network is created and trained. When you click on the "stop" button, the name of the button changes to "start", the training stops and the swingworker is deleted ( which I can't do ) so as not to clog the RAM.
Here is an example:
https://gist.github.com/AshFTW/dca4655135328ff3cf2...
Instead of training the neural network, I create an array that fills the memory. As soon as onTick.cancel(true) is called, the thread is expected to stop and the memory is freed. What should be done,

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
John Ashley, 2016-12-21
@AshFTW

The only solution at the moment is to create your own SwingWorker (thanks to patrick for his MySwingWorker).
From the pros - no longer pops up

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Cannot allocate new FloatPointer(1895946), totalBytes = 80005726, physicalBytes = 3705155584
  at org.bytedeco.javacpp.FloatPointer.<init>(FloatPointer.java:76)
...
  at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.OutOfMemoryError: Physical memory usage is too high (3725254656 > Pointer.maxPhysicalBytes)
...

Of the minuses - the memory is still not released at the end of the thread.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question