How to dispose/delete a LightVirtualFile when not needed?

Answered

I'm using LightVirtualFile (and a CEFbrowser inside) to render some HTML contents. When there's a user action, I'm creating a LightVirtualFile (with the help of FileEditorProvider). When I close this file, I would like to delete this file. LightVirtualFile offers delete(Object requestor) method. When I try to delete, I face runtime exception

PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (psiFile!=null) {
    psiFile.delete();
}

java.lang.UnsupportedOperationException: deleteFile(LightVirtualFile: \CODESPELL.AI.html) not supported by com.intellij.testFramework.LightVirtualFileBase$MyVirtualFileSystem
	at com.intellij.openapi.vfs.DeprecatedVirtualFileSystem.unsupported(DeprecatedVirtualFileSystem.java:157)
	at com.intellij.openapi.vfs.DeprecatedVirtualFileSystem.deleteFile(DeprecatedVirtualFileSystem.java:128)
	at com.intellij.openapi.vfs.VirtualFile.delete(VirtualFile.java:466)
	at com.intellij.testFramework.LightVirtualFileBase.delete(LightVirtualFileBase.java:187)
	at com.intellij.psi.impl.file.PsiFileImplUtil.doDelete(PsiFileImplUtil.java:92)
	at com.intellij.psi.impl.source.PsiFileImpl.delete(PsiFileImpl.java:452)

I'm planning to create a new LightVirtualFile during an action and delete the same on file close. I do not want this File to stay during the lifetime of the project. I'm finding a way to dispose this file when it gets closed. What's your recommendation here?

0
1 comment

Hi,

LightVirtualFiles are in-memory files and cannot be deleted. They should be garbage collected when they are not referenced anymore.

Are they leaking in your case? If so, I suggest profiling your application to find out where the references are stored.

0

Please sign in to leave a comment.