Memory code cleanup

Memory-related code cleanup; no functional change.