How NSMutableString works under the hood ?

I want to understand how it manages memory allocation if i need more memory later than the memory i specified during initialisation . Does it allocates new chunk of memory and dellocate older memory or does it already allocated more memory than i asked for in first place? Just want to understand how exactly this calculation is done ?

And i do initialisation of NSMutableString in swift , will these same principle of expension applied there ?

How NSMutableString works under the hood ?
 
 
Q