Results 1 to 28 of 28

Thread: Hopeless: memory not being released

Hybrid View

  1. #1
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Hopeless: memory not being released

    One other thing to try would be to use a fixed size array. I'd bet that VB is leaking memory from the array allocations. Dynamic arrays have additional overhead in terms of memory allocations, and the redimensions may be the problem. BTW, the preserve keyword actually uses double the amount of memory because it actually copies the entire array into a new array in memory and then (in theory ) deallocates the previous one. If you think about it, it has to work this way to ensure that the new array gets a contiguous region in memory. There is no way of knowing if the additional addresses above the original allocation are free, so it plays it safe and just makes it bigger. You should be OK if you just avoid making memory operations inside your loop.

    See if you can get something like this to work. I collapsed your loop a little bit.

    VB Code:
    1. Dim FullBuffer(BUFFER - 1) As Byte, j As Integer        'additional dims. Assumes BUFFER is a const.
    2.    
    3.     hFile = FreeFile
    4.    
    5.     Open Filename For Binary Access Read As #hFile
    6.         For i = 1 To chunkNum
    7.             'tells us how much is still to be read...
    8.             If (i = chunkNum) Then
    9.                 tempChunkSize = lastChunkSize
    10.             Else
    11.                 tempChunkSize = realChunkSize
    12.             End If
    13.             'get new filename
    14.             sliceFileName = desPath & slicePrefix & Format$(i, formatStr) & "." & fileExt
    15.             aFile = FreeFile
    16.             'open file for write
    17.             Open sliceFileName For Binary Access Write As #aFile
    18.                 Do While (tempChunkSize > 0)
    19.                     'read and write
    20.                     Get #hFile, , FullBuffer
    21.                     If tempChunkSize >= BUFFER Then
    22.                         Put #aFile, , FullBuffer        'write the whole thing.
    23.                     Else
    24.                         For j = 1 To tempChunkSize      'write each byte individually - only doing
    25.                             Put #aFile, , FullBuffer(j) 'this once per file, so the overhead isn't
    26.                         Next j                          'that much.
    27.                     End If
    28.                     'progress forward
    29.                     tempChunkSize = tempChunkSize - BUFFER
    30.                     PB1.value = PB1.value + 1
    31.                     'Erase FullBuffer                   'try uncommenting this as a next step.
    32.                 Loop
    33.             Close #aFile
    34.             'let windows refresh etc.
    35.             DoEvents
    36.         Next i
    37.     Close #hFile

  2. #2

    Thread Starter
    Hyperactive Member TupacShakur's Avatar
    Join Date
    Mar 2002
    Location
    Da Land Of Da Heartless...
    Posts
    493

    Re: Hopeless: memory not being released

    Quote Originally Posted by Comintern
    One other thing to try would be to use a fixed size array.
    [...]
    You should be OK if you just avoid making memory operations inside your loop.
    People, forgive me for using this statement too much: ALREADY TRIED THAT ... It seems this is truely a hopeless case.


    Quote Originally Posted by Comintern
    I'd bet that VB is leaking memory from the array allocations.
    I'd bet VB is leaking memory from all over .


    Quote Originally Posted by Comintern
    I collapsed your loop a little bit.
    I tried this approach, but, as i expected, same problem is occuring. Thanks for ur help guys.
    "And Now I'm Lika Major Threat, Cause I Remind U Of The Things U Were Made To Forget!" - (2PAC)

    "Now They Label Me a Lunatic, Couldn't Care Less, Death or Success is What I Quest, Cause I'm Fearless!" - (2PAC)

    " There's a light at the end of every tunnel, just pray it's not a train!! "



    I am 100% addicted to Tupac. What about you?
    I am 24% addicted to Counterstrike. What about you?
    The #1 Tupac Fans Web Site | The Official Tupac Web Site

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width