EMI: Free materials as soon as they are no longer in use by any costumes

This fixes a crash on save restore introduced by 5c20f0f4a. The crash can be reproduced with the following savegame: https://cloud.githubusercontent.com/assets/757718/3635539/4d9722ec-0f7b-11e4-85aa-c2bd98ee64c9.png (change the suffix to .gsv)

With 5c20f0f4a, the loaded materials were not freed until the actor object was destructed. For example, if materials were loaded by a costume and the actor then switched to another costume, the materials loaded by the former costume were kept around although they were no longer in use.

In Actor save/restore, the list of loaded materials at the time of restoring is expected to match the list of materials at the time of saving. This was not the case if at the time of saving the list contained materials that were loaded by costumes that were no longer active. When restoring, the list will only contain the materials that are loaded by the active costumes. This caused the save restore to go out of sync.

This fix adds reference counting to the materials, so they will be freed as soon as they are no longer referenced by any costumes.