improve resource management

Now resources can be retained and discarded by corresponding subsystems. For example, on Windows platform when device is lost, all resources are released and then recreated.