So, as I understand it, if I declare a public class shared variable, GC will never get rid of it. Is it correct?
Nearly. GC will not clear the line referenced by your shared variable.
If, however, you call ChangeString with a new line, the line pointed to by myString will no longer be embedded in this link and may be eligible for GC. However, a new line (link to newString ) will now be embedded in the myString variable, preventing it from garbage collection.
Would a shared variable now get GCed if there were no class instances?
Not. A common variable is the roots of an object, since it belongs to the "type" of the class, not to any instances.
But what if I change ChangeString as a generic sub?
This will have no effect.
source share