- Use cache
If there are a lot of objects to be allocated and released frequently, you can use cache techinique to record released objects, and reuse them in future.
Be careful:
- You must set a capacity that at most the specified number of objects can be recorded in cache; otherwise, cache will consume to many memory.
- You must design a policy to release some/all cached objects when system is in low memory. - Use chunk
If you need a buffer to append/remove elements frequently, you can split the buffer to multiple chunks. more details, please refer to another thread 'Buffer design'. - xxx