fix #1319 resource provider mistakenly disposed on class unload

If a template class is associated to a template script which uses a
resource provider, the resource provider is mistakenly disposed when
unloading the template class (even if the template script is still
loaded).
This is an issue especially in some skin reloads scenarios, in which
the template script is not reloaded while the template class is reloaded,
which leads to a situation in which the reloaded template can no longer
use the resource provider which was mistakenly disposed.

(cherry picked from commit 3b6bcd9cf48c3a9af4e69ba234bbf1f21109e61c)
1.4.17M