Centralize task resource management in Task.

Working towards #278.