Evenimente
17 mar., 23 - 21 mar., 23
Alăturați-vă seriei de întâlniri pentru a construi soluții AI scalabile bazate pe cazuri de utilizare din lumea reală cu colegi dezvoltatori și experți.
Înregistrați-vă acumAcest browser nu mai este acceptat.
Faceți upgrade la Microsoft Edge pentru a profita de cele mai noi funcții, actualizări de securitate și asistență tehnică.
Possibly incorrect assignment to local 'variable' which is the argument to a using or lock statement. The Dispose call or unlocking will happen on the original value of the local.
There are several scenarios where using
or lock
blocks will result in a temporary leak of resources. Here is one example:
thisType f = null;
using (f)
{
f = new thisType();
...
}
In this case, the original value, such as null, of the variable thisType
will be disposed of when the using
block finishes executing, but the thisType
object created inside the block will not be, although it will eventually get garbage collected.
To resolve this error, use the following form:
using (thisType f = new thisType())
{
...
}
In this case, the newly allocated thisType
object will be disposed of.
The following code will generate warning CS0728.
// CS0728.cs
using System;
public class ValidBase : IDisposable
{
public void Dispose() { }
}
public class Logger
{
public static void dummy()
{
ValidBase vb = null;
using (vb)
{
vb = null; // CS0728
}
vb = null;
}
public static void Main() { }
}
Feedback pentru .NET
.NET este un proiect open source. Selectați un link pentru a oferi feedback:
Evenimente
17 mar., 23 - 21 mar., 23
Alăturați-vă seriei de întâlniri pentru a construi soluții AI scalabile bazate pe cazuri de utilizare din lumea reală cu colegi dezvoltatori și experți.
Înregistrați-vă acum