how heap memory works