I think setting unused components to invalid (or out of scope) would be the first step. To be successful, there must be no variables pointing to the now-unused element.
If the elements are not part of a circular reference, they should be freed immediately. If they are part of a circular reference, the garbage collector may need to run. In most circumstances, the automatic call of the garbage collector should be sufficient. See "
Garbage Collection"