JavaFX leaking memory through dirtynodes - memory-leaks

I have a javafx desktop application which after some time of usage accumulates a lot of objects in dirtynodes[] in one of the Scenes. Eclipse's tool MAT recognised this as a suspicious situation and possible leak. It is using 170 MB of memory which in my case is 30%. There are periodical updates of the nodes in that scene. Is there something I can do about this? Do those dirtynodes get cleaned? I am using java 8 u 51.

Dirty nodes are nodes in a scene which have been invalidated. They are processed once per frame so if JavaFX Application Thread (UI thread) is busy then the synchronization of dirty nodes cannot happen.
We had an issue in a screen with listview where every cell of the listview contained many rectangles and texts. The whole listview contained a few hundreds of nodes.
Cells in listview are not supposed to be reused but to be created every time the listview is repainted. When the listview had many lines and an user was holding scrollbar and moving it for a minute then synchronization of dirty nodes could not happen and we got out of memory exception because there were hundreds of tousends dirty nodes.
So my suggestion is to check if you are not blocking JavaFX Application Thread while adding the nodes to it.
Good practice is to create nodes in background thread and add it scene in UI thread.

Related

How can I make Timeline / Application Thread notify waiting Threads

I have a big Problem with multithreading...
I develop a little game and I have a Timeline wich updates for example Coordinates of every Sprites in my Application... Now I want to use another Thread which listens to my Keyboard and changes some Coordinates from a GameObject... But the Coordinates change way to often (about 6,8 million Times per second, because the Thread is too fast...). Can I make this Thread wait till the Application Thread has updated the Sprite Coordinates?
Is there any other solution for my Problem?
Thanks

Can there be multiple rendering worker threads

I've recently come across the Worker & WorkerDomain classes available to AS3, however there doesn't seem any mention of how each thread interacts with whats being rendered on screen.
Is there a way to render to the screen on one thread, then after an
event switch rendering to the other thread?
My initial assumption is threads apart from the "Primordial" thread should only be used for background processing, but I'm hoping that may not be the case.

openGL volume rendering and display update in different thread

I am using openGL and "freeglut" library for volume rendering and display. In the main thread I initialize the openGL window, and then acquire volume data frame by frame, the volume rendering is done after one volume data is acquired. This works well but takes much time. Is it possible that I keep initializing openGL window in the main thread, and do the volume rendering and display in another thread? I have checked wglMakeCurrent, it does not update the window initialized in the main thread.
Multithreaded OpenGL operation is a nasty beast. You can however, and this is what I strongly suggest, map a Pixel Buffer Object into the program's address space. And that region of address space is visible to all threads. So you can update the volume data from another thread (or, like in the case of the program I'm currently working on, on another GPU), then signal the main thread to update the texture from the new data in the PBO. You can also update only sub portions of the volume from the PBO with glTexSubImage3D.

Effective Communication between Worker and UI Threads

I am designing real-time windows application displaying graphics or images gotten from multiple sensors. I assigned a thread for getting data from each sensor, and a UI thread for each display. According to MSDN, I can employ PostThreadMessage to send a message to another thread.
That sounds fine but in my architecture, a worker thread needs to send lots of information such as image. So I don't think I can send single big image data to UI thread with PostThreadMessage because the worker thread has to hold that data until corresponding UI thread processes it.
If so, what is best way to send the large amount data from worker thread to UI thread?
I thought about saving it as a file but I am sure it can be big bottleneck as it requires to process the data very quickly.
One idea I have is to send very small part, for example, few lines of image, when you send a message from worker thread.
Any advice would be appreciated.
my comment as an answer:
As jeffamaphone wrote, use the pointer to the memory instead of copying everything. Thats the advantage of threads - shared memory - dont waste it.
Leave the freeing of the images memory to the ui-thread, and allocate new memory for the next image in the worker thread. So the worker thread does not have to wait until the ui-thread is finished with the image. Requires more memory, but no copying or long waits will be necessary.
There are possible improvements, which can reduce the number of allocations you will have to make, but they are quite fiddly - and its quite doutable that they indeed would improve performance, because they would reintroduce some kind of synchronisation. So i would go ahead and implement it like i suggested, and if you notice that the amount of memory allocations is a performance bottleneck, you/we can rethink this matter.

QGLWidget's paintGL() method called from which Qt thread?

suppose I use the QGLWidget's paintGL() method to draw into the widget using OpenGL. After the Qt called the paintGL() method, it automatically triggers a buffer swap. In OpenGL, this buffer swap usually blocks the calling thread until the frame rendering to the background buffer is completed, right? I wonder which Qt thread calls the paintGL as well as the buffer swap. Is it the main Qt UI thread? If it is, wouldn't that mean that the block during the buffer swap also blocks the whole UI? I could not find any information about this process in general..
Thanks
I don't use the QGLWidget very often, but consider that yes, if swapBuffers() is synchronous the Qt GUI thread is stuck. This means that during that operation you'll be unable to process events.
Anyway, if you're experiencing difficulties while doing this, consider reading this article which manage to allow multithreaded OpenGL to overcome this difficulty.
Even better, this article explains well the situation and introduces the new multithreading OpenGL capabilities in Qt 4.8, which is now in release candidate.
In OpenGL, this buffer swap usually blocks the calling thread until the frame rendering to the background buffer is completed, right?
It depends on how it is implemented. Which means that it varies from hardware to hardware and driver to driver.
If it is, wouldn't that mean that the block during the buffer swap also blocks the whole UI?
Even if it does block, it will only do so for 1/60th of a second. Maybe 1/30th if your game is slowing down. If you're really slow, 1/15th. The at most one keypress or mouse action that the user gives will still be in the message queue.
The issue with blocking isn't about the UI. It will be responsive enough for the user to not notice. But if you have strict timings (such as you might for a game), I would suggest avoiding paintGL at all. You should be rendering when you want to, not when Qt tells you to.

Resources