Remove allocated memory after invoking backend functions