It is Java where you are stuck. Not GC languages in general.
It is Java where you are stuck. Not GC languages in general.
PJSIP[1] has an interesting approach to this. SIP messages have lots of strings associated with them, are usually relatively short-lived, and typically you'll want to modify these strings or attach new ones. PJSIP does this by hanging a string arena off of each SIP message object.
As you add strings to the SIP message, these get appended to the arena, which is grown automatically as and when it needs to be. If you delete a string, it just sticks around in the arena unused. Arena space can also be shared, e.g. if you copy a substring from one SIP header to another, it'll just be referred to twice using a pointer and length.
Finally, when you free the SIP message, it just frees the entire arena in one go.