Yes. It is interesting that this is an issud which has been around at least back to Java 5.0 (2004) but is a real problem for a few people now. Possibly because they are using chronicle in long running applications.
The cleaner *used* to unmap this mapping but now calls through to code which does nothing.
I will look at using a cleaner or finaliser if I have to. I will use a resource counter for unmapping without a GC. I have to check this doesn't conflict with the current unmapping mechanism I.e. it doesn't crash the GC.
I have to check this gives the desired behaviour on windows and linux.
Hi Peter,
it is strange that we all on the same problem at the same time :)
So .. What will you do even you know there is no reference to the buffer, actually in our case we know that no one else is using the buffer.
İ think we can use cleaner from unsafe, what do you think?
On Jan 16, 2014 9:42 PM, "Peter Lawrey" <peter....@higherfrequencytrading.com> wrote:
This is common problem with Java's implementation of memory mapped files. It requires a stop the world collection to determine when a memory mapping can be unmapped.
This is high on my todo list to create a library or add to JavaLang to solve this, most likely by using reference counts to track when the buffer is not needed.
The risk is that if you unmap and use the address later the while JVM crashes (not just throw an error)
BTW I was thinking about this problem this morning. 😋
On 16 Jan 2014 19:25, "Yavuz Gökırmak" <yavuz.g...@intellica.net> wrote:Hi Peter,I have a problem about memory mapped files, I think you may hit the same problem and solved somehow :)I create randomAccessFile and then map this file to a bytebufferfileChannel = new RandomAccessFile("testbug." + i, "rw").raf.getChannel();byteBuffer = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0,1 * 1024 * 1024 * 1024);when I need to delete the file, I close the channel and delete the filefileChannel.close();File file = new File("testbug." + (i - 1));deleted = file.delete();although java thinks that the file is deleted, it still remains space on the disk. I can see the file as "DEL" at the lsof outputevam@HURBIGENG04:~/evamengine$ lsof | grep testbash 16465 evam cwd DIR 252,0 4096 1974273 /home/evam/bugtestjava 20073 evam cwd DIR 252,0 4096 1974273 /home/evam/bugtestjava 20073 evam mem REG 252,0 1073741824 1973734 /home/evam/bugtest/testbug.9java 20073 evam DEL REG 252,0 1973733 /home/evam/bugtest/testbug.8java 20073 evam DEL REG 252,0 1973732 /home/evam/bugtest/testbug.7java 20073 evam DEL REG 252,0 1973731 /home/evam/bugtest/testbug.6java 20073 evam DEL REG 252,0 1973730 /home/evam/bugtest/testbug.5java 20073 evam DEL REG 252,0 1973729 /home/evam/bugtest/testbug.4java 20073 evam DEL REG 252,0 1973728 /home/evam/bugtest/testbug.3java 20073 evam DEL REG 252,0 1973727 /home/evam/bugtest/testbug.2java 20073 evam DEL REG 252,0 1973726 /home/evam/bugtest/testbug.1java 20073 evam DEL REG 252,0 1973698 /home/evam/bugtest/testbug.0The problem is A mapped byte buffer and the file mapping that it represents remain valid until the buffer itself is garbage-collected. So in order to actually delete the file I have to callbyteBuffer = null;System.gc();this is the same problem ( http://stackoverflow.com/questions/2972986/how-to-unmap-a-file-from-memory-mapped-using-filechannel-in-java )here is my code that reproduces the problemand this is the solutiondo you have any advice without using system.gc()regards