How can I ensure the destruction of a String object in Java?

前端 未结 9 982
感情败类
感情败类 2020-11-30 04:36

An empoyee at my company needs to modify data from a SQL Server database through a program I made. The program used Windows authentication at first, and I asked the DBAs to

9条回答
  •  时光说笑
    2020-11-30 05:08

    if you absolutely must, keep a WeakReference to the string, and keep gobbling memory until you force garbage collection of the string which you can detect by testing if the weakreference has become null. this may still leave the bytes in the process address space. may be a couple more churns of the garbage collector would give you comfort? so after your original string weakreference got nulled, create another weakreference and churn until it is zeroed which would imply a full garbage collection cycle was done.

    somehow, i have to add LOL to this even though my answer above is entirely serious :)

提交回复
热议问题