API for triggering cleanup process when app is deleted

Is there some way to trigger a cleanup process when an app is deleted (moved to the Trash)? It seems that there is...but I can't seem to find what API or mechanism to use.