c# - How Marshal.FreeHGlobal can free unmanned array? -
i have reserved unmanned array using:
intptr ptr = marshal.allochglobal(marshal.sizeof(array[0]) * array.length); then free using:
marshal.freehglobal(ptr ); as far read, free memory correctly , no memory leak gonna happen. question: true? if is, how works? marshal state-full , store meta-data every reserved data?
the allochglobal method exposes localalloc function. , freehglobal method exposes localfree function. memory management not being done managed component. done code behind these windows api functions.
to answer question: yes has keep track of allocated size. can retrieve size of handle calling localsize function. honest, don't know how being done internally, don't need know that.
Comments
Post a Comment