I realize that garbage collection is a means to determine if a portion of memory needs to be deallocated or not. The simplest example I know of is setting a variable to
var x = 'foobar'; // x)-┐ // V // ┌-┬-┬-┬-┬-┬-┐ // |f|o|o|b|a|r| // └-┴-┴-┴-┴-┴-┘ x = null; // x)--> null // // ┌-┬-┬-┬-┬-┬-┐ // |f|o|o|b|a|r| Eligible to be garbage collected // └-┴-┴-┴-┴-┴-┘
To further illustrate my contrived example, let's say I want to store a password but then securely obfuscate it before I send it into garbage collector land. I believe Reassignment would look like this:
var x = 'foobar'; // x)-┐ // V // ┌-┬-┬-┬-┬-┬-┐ // |f|o|o|b|a|r| // └-┴-┴-┴-┴-┴-┘ x = '******'; // x)--------------┐ // V // ┌-┬-┬-┬-┬-┬-┐┌-┬-┬-┬-┬-┬-┐ // |f|o|o|b|a|r||*|*|*|*|*|*| // └-┴-┴-┴-┴-┴-┘└-┴-┴-┴-┴-┴-┘ // \_________/ // | // Eligible for garbage collection x = null; // x)--> null // // ┌-┬-┬-┬-┬-┬-┐┌-┬-┬-┬-┬-┬-┐ // |f|o|o|b|a|r||*|*|*|*|*|*| // └-┴-┴-┴-┴-┴-┘└-┴-┴-┴-┴-┴-┘ // \_________/ \_________/ // | | // Eligible for garbage collection
So can I manipulate the first memory partition so that the values are not left in memory unreferenced but instead replaced so a memory scan would find the replacement instead of the old value?