Proper Disposal of Unamanged Struct

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 19:59:59

问题


Hello this question is a continuation of this question. Provided below is a short version of the code that is loading the data into the structure. The HDF5DotNet library is found here using the 32 bit version with vs2015. My question is, will MyStruct leak memory when SomeCallerClass call HDF5GetSubGroups?

using HDF5DotNet;
namespace CommonClass
{
        public class HDF5FileReader
        {
             public static List<string> HDF5GetSubGroups(string filePath)
             {
                  var returnList = new List<string>();
                  //... some HDF5 instantiating -- commented out for brevity
                  var myStruct = new MyStruct[numberOfThingsToRead];
                  H5A.read(someAttribute, someAttributeType, new H5Array<MyStruct>(myStruct));
                  string myStructVariableString = IntPtrToString(myStruct[0].intPtr);
                  returnList.Add(myStructVariableString);
                  //... closing some HDF5 instantiating -- commented out for brevity
                  return returnList
             }

         private string IntPtrToString(IntPtr ipp)
         {
              string s = Marshal.PtrToStringAnsi(ipp)
              //need to free ipp?
              return s;
         }
     }

     public struct MyStruct
     {
          public Int int1;
          public IntPtr intPtr;
     }
}

namespace CallerClass
{
     public class SomeCallerClass()
     {
         string someFilePath = "Path\To\HDF5File.h5"
         var stringList = HDF5FileReader.HDF5GetSubGroups(someFilePath)
         //Do Something with StringList -- add to observablecollection
     }

     public class UnloadingSomeCallerClass()
     {
          //Clear the observablecollection
     }

}

来源:https://stackoverflow.com/questions/50243898/proper-disposal-of-unamanged-struct

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!