-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use of File.deleteOnExit leaks memory #13
Comments
@glassfishrobot Commented |
@glassfishrobot Commented |
@glassfishrobot Commented For long-running server processes, using deleteOnExit is not appropriate, due to the memory leak. It's a better tradeoff to actually leak the files in the rare event of a crash, than it is to constantly leak memory during normal operations. If your target is Java 7+, you could also open files with the "delete on close" hint: http://docs.oracle.com/javase/7/docs/api/java/nio/file/StandardOpenOption.html#DELETE_ON_CLOSE |
@glassfishrobot Commented |
@glassfishrobot Commented tempFile.deleteOnExit(); |
@glassfishrobot Commented |
@glassfishrobot Commented |
@noppo0831 Commented Problem
environmentJava 7, Java 8, Java 9(build 9+181) Cause
String suffix = config.getTempFileSuffix();
File tempFile = TempFiles.createTempFile (prefix, suffix, config.getTempDir());
// delete the temp file when VM exits as a last resort for file clean up
tempFile.deleteOnExit();
if (LOGGER.isLoggable (Level.FINE)) {
LOGGER.log (Level.FINE, `Created temp file = {0}`, tempFile);
}
public void deleteOnExit() {
SecurityManager security = System.getSecurityManager();
if (security! = null) {
security.checkDelete(path);
}
if (isInvalid()) {
return;
}
DeleteOnExitHook.add(path);
}
The code of static synchronized void add (String file) {
if (files == null) {
// DeleteOnExitHook is running. Too late to add a file
throw new IllegalStateException (`Shutdown in progress`);
}
files.add (file);
}
Therefore, memory of the size of Solution ideaNO1.
Advantages: There are few changes NO2.There is an idea in the above URL. Advantages: temporary files do not disappear even if VM is shut down before dataHead.dataFile.close is called No.3.Like No2., we extend and add Advantages: There are fewer code changes than No2. I recommended No3. |
@jingtingjian Commented |
|
@glassfishrobot @Tomas-Kraus Any ETA on when the issue will be fixed? |
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
The method MemoryData.createNext calls File.deleteOnExit. Unfortunately, this permanently adds an entry to a list of files. In our long running server application, the end result is a significant memory leak.
In our case, we don't have much use for this call to deleteOnExit anyway, as our system already cleans up all temporary files when the server stops. So if there is no better way, I would request a simple system property to disable this call.
Affected Versions
[1.9.4]
The text was updated successfully, but these errors were encountered: