Who Disposes of an IDisposable public property?

前端 未结 10 1623
萌比男神i
萌比男神i 2020-12-03 09:59

If I have a SomeDisposableObject class which implements IDisposable:

class SomeDisposableObject : IDisposable
{
    public void Dis         


        
10条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-03 10:26

    Design you have mentioned here is not something could handle this scenario. You said there is a container for that class then it should dispose it along with itself. If other objects may be using it then it is not the container and scope of you class widens and it need to dispose at boundary of that scope.

提交回复
热议问题