KilianB / GoogleTranslatorTTS

Converts a string of text to mp3 files utilizing the google translator text to speech api. Fast prototyping library without fees or rate limit.
MIT License
5 stars 3 forks source link

Temporary files are not deleted on windows due to bug in MappedByteBuffer #1

Open KilianB opened 6 years ago

KilianB commented 6 years ago

As stated in https://bugs.java.com/view_bug.do?bug_id=4715154 the byte buffer fails to close and doesn't release resources allowing us to delete the file. This will in turn result in turn lead to creating music files with the same name throwing an error.

https://github.com/KilianB/GoogleTranslatorTTS/blob/861e4efab981755f97a94ae7ce0e9a8fced1155d/src/main/java/com/github/kilianB/apis/googleTextToSpeech/GoogleTextToSpeech.java#L425

Possible workaround:

  1. Acknowledged in https://bugs.openjdk.java.net/browse/JDK-8171377 we can use the unsafe invokeCleaner call. This does make us depended on sun.misc and doesn't really contribute to a stable library.
  2. Null reference and trusting System.gc() to actually run garbage collection and free the resource. Gc's may not take the hint and constant garbage collection may become expensive.
  3. Don't used mapped byte buffers at all. -> Check performance implications.
KilianB commented 6 years ago

0a5e0c3f15379889f3dfb4024f4f0effaa461ab2 Implement workaround 1 & 2 with a static flag letting the user change which strategy to use. Default to ` unsafe.incokeCleaner`