Memory optimization and deserialization issue