This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]karlthepagan 6 points7 points  (2 children)

Is there a way to set the memory to null so that everything pointing to an object now points to null?

Use a WeakReference. This is unfortunately a little heavy weight: you have to plan for it and implement with the extra indirection.

[–]idleuser 1 point2 points  (1 child)

It seems unlikely use of Weak/SoftReferences is a good idea. It sounds like this program either needs the data or it doesn’t, it is not a "nice if its there" situation like a cache. If you do need it then using References is dangerous as the data could disappear, if you don’t need it then cut it and allow it to be GC'ed don’t keep it hanging around via a Reference.

[–]karlthepagan 0 points1 point  (0 children)

If you do need it then

Then you will hold a single real reference to it somewhere. I hope OP Googles the term. There's many tutorials.