В основном у меня есть несколько функций, которые выглядят следующим образом:
class MyClass
{
void foo()
{
using (SomeHelper helper = CreateHelper())
{
// Do some stuff with the helper
}
}
void bar()
{
using (SomeHelper helper = CreateHelper())
{
// Do some stuff with the helper
}
}
}
При условии, что я могу использовать один и тот же ресурс, а не другой [instance] в каждой функции, нормально ли это с точки зрения очистки и т.п.?:
class MyClass
{
SomeHelper helper = CreateHelper();
// ...foo and bar that now just use the class helper....
~MyClass()
{
helper.Dispose();
}
}