function validateMemory() {
  // Run garbage collection after each test.
  gc();

  strictEqual(memory.protected.size, 0,
    'Should not leave leftover protected elements in memory');

  strictEqual(memory.allocated.size, 0,
    'Should not leave leftover element allocations in memory');

  strictEqual(memory.free.size, size,
    'Should bring the free pool size back to the default');

  strictEqual(StateCache.size, 0, 'The state cache should be empty');
  strictEqual(NodeCache.size, 0, 'The node cache should be empty');
  strictEqual(MiddlewareCache.size, 0, 'The middleware cache should be empty');

  // Ensure specific middleware caches are empty as well.
  strictEqual(CreateTreeHookCache.size, 0, 'The create tree hook cache should be empty');
  strictEqual(CreateNodeHookCache.size, 0, 'The create node hook cache should be empty');
  strictEqual(SyncTreeHookCache.size, 0, 'The sync tree hook cache should be empty');
  strictEqual(ReleaseHookCache.size, 0, 'The release hook cache should be empty');
}
Validates that the memory has been successfully cleaned per render.