How to use dispose to release resources in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to use dispose to release resources in java?

I have an attached code and its exception maybe it not relevant in Sololearn discussions or questions but it a problem I'm facing hoping fellow programmer can help me with. The code is based on Tesseract tess4j version 4.5.4 in java 8. I take screenshot using BufferedImage. On average the screenshot is taken every 5 seconds daily then read image text for every screenshot taken. The images are not saved on file. For now I'm testing this code on a virtual machine which I'm running it for two weeks consecutively and everything is working fine until the 3th or 4th day of testing. I then get the the attached exception. When I use the "dispose" to dispose of the instance and start a new one. The Eclipse system says "create dispose method" does this method not internally available? Code: https://code.sololearn.com/cVJOG66IePq0/?ref=app Exception: https://code.sololearn.com/c6Za6rrcOrZn/?ref=app

27th Nov 2022, 5:08 AM
Sibusiso Mbambo
1 Answer
0
You declared solo dispose may you need to write object.dispose(); A other thing is dispose() comes from javax.swing.JFrame lib so maythis just work with a JFrame window Beside that you didnt display your img somewhere so i believe you didnt need to dispose if you want „delete“ is just asign the variable as null or asign a new value to it Hopefully that helps Happy coding ✌️😉
27th Nov 2022, 2:44 PM
S3R43o3
S3R43o3 - avatar