more careful memory management