title: Prevent the OS from swapping objects to virtual memory/disk in Java?
body: <p>So I have a program that has the user enter a passphrase. I only hold the passphrase for a few seconds in a <code>char[]</code> before overwriting it but I was wondering if there was a way in Java to prevent the OS from swapping this bit to disk/virtual memory/any more permanent storage than RAM? Research on the topic seems to say no, there is not a way but no where has given me a straight answer yet. I'm also not sure if I can achieve this by using mlock() somehow or by keeping a reference to the value active until I no longer need it. </p>
  
  <p>Thanks!</p>