Fix memory callbacks being garbage collected