Remember FHIR is a very immature 'standard'.
If you jump on the bandwagon, you must be prepared to be agile.
You talk about R5, but R6 is well on its way and, since they actually are STU4, 5, 6 and so on, there is no FHIR 1.0
Some standard bodies opt for stability like Nictiz in the Netherlands, where most of the official specifications are still based on STU3.
Opting for implementation of an immature standard ,one must be prepared for (extreme) agility, otherwise we are all ending op with in-operability because of different incompatible implementations.
> I want to remove the object from memory even if it is still referenced in memory
That makes no sense and it is not possible, it would invalidate every other variable or object property that references it.
But why do you want to do this?
The start tag would be right after the XML declaration, i.e. <StartTag (the element name ends when a space is encountered), the end-tag would then be </StartTag. From there find the closing bracket >