[sc-memory] Cleanup code. Add element free lock (one element free at the time)