请问如下代码有无内存泄漏?为什么?
请问如下代码有没有内存泄漏?其中的str1,str2占用的内存,最终有没有被垃圾回收掉?为什么?我要求比较有理由的,比较有说服力的,比较权威的答案。
static void SearchRecord()
{
int id;
Console.WriteLine( "\nPlease enter the record id to be searched: ");
try
{
id = Convert.ToInt32(Console.ReadLine());
}
catch
{
id = -1;
}
Console.WriteLine( "Your input id is {0}. ", id.ToString());
string str1 = new string( '0 ', 1024);
string str2 = new string( '0 ', 1024);
TB001 tb = new TB001();
unsafe
{
fixed (byte* pstr1 = &(Encoding.ASCII.GetBytes(str1)[0]), pstr2 = &(Encoding.ASCII.GetBytes(str2)[0]))
{
int nRet = tb.SearchRecord(id, (sbyte*)pstr1, (sbyte*)pstr2);
switch (nRet)
{
case 0: