Comments (17)
Completed pending some further testing.
from vlcj.
No ill effects observed with these changes.
from vlcj.
See #100. This has been undone for now.
from vlcj.
New version 3.5.0 of JNA supposedly has some changes for this. Reopening for investigation...
from vlcj.
Maybe provide a system property to enable the different behaviour at the client application's request.
from vlcj.
Just noticed this as well. With JavaFX 8, the copying of the buffer to a JavaFX Canvas is working very well, even for full screen playback (1920x1080), but I did notice that 3 threads are being created for each frame (lock, display, unlock).
It doesn't seem to impact performance noticably on my setup, but it is a shame as it means threads are constantly created / destroyed making it hard to debug or keep track of important threads. I don't quite understand why JNA can't just pool these threads or threadwrappers.
from vlcj.
Please see also the referenced issue #100 for some more information - I already tried to address this but I ended up with thousands of Thread instances that never got garbage collected - I think that is a worse situation.
from vlcj.
I read it, I was looking into it as well. I even asked Timothy Wall
about it, but he seems to think that atleast with JNA 3.5.0 this
shouldn't happen, see
https://groups.google.com/forum/#!topic/jna-users/95p-KeaoLxQ
On 31/07/2013 17:06, Mark Lee wrote:
Please see also the referenced issue #100
#100 for some more information
- I already tried to address this but I ended up with thousands of
Thread instances that never got garbage collected - I think that is a
worse situation.—
Reply to this email directly or view it on GitHub
#52 (comment).
from vlcj.
I just re-tested this.
You can either have the situation now with lots of short-lived Thread instances created which will all be properly garbage collected; or, if you enable the CTI, you get a guaranteed memory leak of two thread instances each time you play media.
Note also that my understanding is that the Thread instances are just proxies that get associated with a native thread as needed - consequently it has been suggested that there is no heavyweight overhead with this approach. In this sense, creating the Thread instance is no different from creating e.g. a temporary String or any other short-lived object.
I think a guaranteed memory leak is worse than the noisy Thread instance creation.
I would be very happy if this could be made to work with a CTI, but I don't really know what to do about it because of the leak that would be incurred.
from vlcj.
Yes, this is exactly what Timothy claims shouldn't happen. It might be a problem with how VLC handles their native threads. They could perhaps be using a pool and a new thread is used for each playback and the old one doesn't die but is re-added to the pool -- in that case the number of threads should be limited. Or perhaps VLC itself is leaking the threads.
I agree with you that a guaranteed memory leak is worse. I'll have to check what kind of overhead this 'lightweight' thread causes in the case of the lock/display/unlock for each frame, but I suppose it will be overshadowed by the frame buffer created at the same time.
from vlcj.
The leak could be a problem with the way I've implemented it in vlcj. I have to admit I've not really looked into this in great detail.
from vlcj.
As part of the major refactoring for vlcj-4 under #690, I have used CallbackThreadInitializers. The thread model as a whole has changed, so maybe it's OK this time.
This issue will remain open for now as a reminder to test what happens with vlcj-4.
from vlcj.
I have a nagging doubt that right now even with the new implementation this is still going to be a problem - e.g. each time you play new media and add a listener, there may be an undetached unused thread left over.
Needs some careful testing.
At least now with the media and media player handling their own events separately, this issue might only affect changing media - and the CTI could be removed in that case but remain in the media player case.
from vlcj.
Some initial profiling results... bearing in mind that no listeners are attached to the media event manager.
It is encouraging but not 100% clear.
Even after forcing garbage collections, it first appeared that each time media was started, a new CTI was created and not cleared - however, after waiting a little longer those CTI did indeed appear to be garbage collected.
Further testing is required, and especially for the case when adding listeners to the media (as this involves another event manager).
from vlcj.
Even though no listeners are being attached to the media event manager in the current implementation, the callback thread is still being created.
I am seeing inconsistent results, maybe attributable to caching, as what appears to happen now is when repeatedly playing new media you will get a new CTI created until you get, say, 10 of them, at which point some of them (not all of them) will disappear.
So presently it appears to be the case that the CTI instances will grow for a time before eventually being cleared away leaving 2 CTI instances related to the media event manager. It will then grow again, and eventually come back to leaving 2 CTI instances.
I can change the implementation so that CTI is not needed until the listener is added, which would be a Good Thing to do.
Further testing is still needed when a media listener is added.
from vlcj.
I changed the implementation at 4be8e3c to only create the callback and the CTI if there was at least one listener, and to explicitly invoke detach on the CTI when all the listeners were removed.
from vlcj.
Latest test adds a listener to each media as it is played (and makes sure to remove it at the appropriate time).
Inspecting the heap dump shows no ongoing increase in CTI instances.
It bizarrely seems to keep one extra, which I don't quite understand, but the good news is there is no apparent long term leak.
So finally I am happy to close this issue as the new implementation for vlcj-4 seems sound.
The outstanding issue of the seemingly 1 "extra" instance hanging around can be looked at in a more general profiling task later, it could be attributed to pooling, I'm not sure.
from vlcj.
Related Issues (20)
- Transparent Overlay on Pi 4 and Pi 5 HOT 1
- Transparent Overlay on Pi 5 with Java 22 gets shifted upwards...
- Integrate new fit-mode native API HOT 2
- Reconsider not using native get aspect ratio
- How to set the transparency for EmbeddedMediaPlayerComponent? HOT 4
- How to repeat play video without black frames between plays
- How to play videos with alpha channel? HOT 1
- New native API to set teletext transparency HOT 1
- Playing two files in sync HOT 2
- for some strream length returned stay at 0 HOT 3
- Embedded subtitles does not show on macOS HOT 28
- Support new "jump time" native API HOT 1
- Significant performance problem if the window is large HOT 14
- strange blue filter on vlcj5 HOT 10
- Some Questions HOT 3
- [question] why can't get time change event from MediaPlayerEventAdapter when video is psused HOT 2
- Compiled using MacOS IntelliJ for vlcj4.8.3 and vlcj-javafx1.2.0. No problem running on MacOS but have problem on Ubuntu 22.04 vlc 3.0.20 HOT 11
- Check native change for callback media HOT 1
- How to use vlcj 5.0? HOT 6
- [3.0.19] JVM crash on Mac Arm after every controls().stop() HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vlcj.