Jwang add resource measurements

1. The code that tracks `memSize` needs to not run when the resource profiling is not enabled.
2. You don't seem to handle mutation of the strings. What happens when the string is replaced?