[VB.NET]救命,mStream.Write()执行完后,内存不能释放.急呀.

前端之家收集整理的这篇文章主要介绍了[VB.NET]救命,mStream.Write()执行完后,内存不能释放.急呀.前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
救命,mStream.Write()执行完后,内存不能释放.急呀. 下面是贴的函数,目的就是想拷贝一些数据到MemoryStream中,执行完For循环后,内存增加了几百M. 但无论如何也释放不了. 除非关闭程序. 请教有没有人知道程序的毛病是出在哪里呀?! 在线等,解决完立刻给分! 谢谢呀! Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click Dim mStream As MemoryStream Dim nData As Integer = 40960 Dim iPtr As Integer Dim PACKET_SIZE As Int16 = 4096 Dim readBuffer(PACKET_SIZE) As Byte For iPtr = 0 To PACKET_SIZE - 1 readBuffer(iPtr) = 255 Next mStream = New MemoryStream While nData > 0 mStream.Write(readBuffer,PACKET_SIZE) nData -= 1 End While mStream.Close() mStream.Dispose() End Sub __________________________________________________________________________ 帮顶的也有分.不够再加! 急. __________________________________________________________________________ 又见VB 帮顶接分! __________________________________________________________________________ UP UP UP 抬起头 __________________________________________________________________________ up __________________________________________________________________________ Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click Dim mStream As System.IO.MemoryStream Dim nData As Integer = 40960 Dim iPtr As Integer Dim PACKET_SIZE As Int16 = 4096 Dim readBuffer(PACKET_SIZE) As Byte For iPtr = 0 To PACKET_SIZE - 1 readBuffer(iPtr) = 255 Next mStream = New System.IO.MemoryStream While nData > 0 mStream.Write(readBuffer,PACKET_SIZE - 1) nData -= 1 End While ''mStream.Flush() mStream.SetLength(0) mStream.Close() mStream = Nothing ''强调进行垃圾回收 GC.Collect() End Sub 对你的代码进行了点改动: 1.mStream.Write(readBuffer,PACKET_SIZE - 1) 2. GC.Collect() __________________________________________________________________________ 结帐,谢谢楼上的几位朋友! __________________________________________________________________________ 原文链接:https://www.f2er.com/vb/263978.html

猜你在找的VB相关文章