Affects Version/s: 7.0.X, Master
java.io.DeleteOnExitHook will cause memory leak. Please refer to
Steps to reproduce
- Enable DBStore setting in portal-ext.properties
- Connect it to an empty Oracle database
- Start liferay
- Add the "Documents and Media" portlet into the home page
- Go to "Liferay DXP Site > Content > Documents and Media"
- From Terminal, get one heap dump
(windows: jmap -dump:format=b,file=heapdump.hprof <pid>)
- Upload several image files into Documents and Media
- Go back to the home page and confirm uploaded files are displayed
- From Terminal, get another heap dump
- Run "Eclipse Memory Analyzer" and open the heap dumps
- Click on "Histogram" button
- In Class Name column's Regex, filter with "LinkedHashSet"
- Note 1 record will show
- Right-click on it and select "Search Queries..."
- Type "hash_" and double-click on "Hash Entries"
- Leave all defaults and click Finish
- On Key column's Regex, filter by "liferay-dxp" (liferay-dxp is your liferay-home folder name)
- Note the Key value belongs to temporary files (for example, D:\liferay_home\tomcat-9.0.6\temp\20180418021641041KOPOJNRH).
- Confirm the number of resulted entries grows from dump1 to dump2
- Upload more images, display them and take heap dump again to see it keeps increasing
LinkedHashSet keeps growing, leaking memory and potentially leading to OutOfMemory error.
LinkedHashSet doesn't include the temp files value.