Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Captain! I think she's leaking memory

Captain! I think she's leaking memory

Scheduled Pinned Locked Moved C#
helpperformancelearning
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sameerhanda
    wrote on last edited by
    #1

    ok, good people..i have a following line of code.. using( MemoryStream mStr = new MemoryStream( ) ) { try { mStr.Capacity = totalByteCount ; } } Of course the dude i got inherited this code from is trying to put 141372000 in the memory buffer i.e the capacity. At this point i get the following error Exception of type System.OutOfMemoryException was thrown." } I am at a total loss. Have tried different things...So i throw a hail mary over to the code porject dudes. Thanks for your help Sameer

    W J 2 Replies Last reply
    0
    • S sameerhanda

      ok, good people..i have a following line of code.. using( MemoryStream mStr = new MemoryStream( ) ) { try { mStr.Capacity = totalByteCount ; } } Of course the dude i got inherited this code from is trying to put 141372000 in the memory buffer i.e the capacity. At this point i get the following error Exception of type System.OutOfMemoryException was thrown." } I am at a total loss. Have tried different things...So i throw a hail mary over to the code porject dudes. Thanks for your help Sameer

      W Offline
      W Offline
      WillemM
      wrote on last edited by
      #2

      Isn't it possible just use the following code: using(MemoryStream stream = new MemoryStream()) { for(int i= 0; i < totalByteCount; i++) { stream.Write(new byte[] { 0 },0,1); //Not sure about this call, haven't got the docs here and I'm too lazy to remember :P } stream.Seek(0,...); } This simply fills the stream with zeroes and resets the stream to the beginning. This way the capacity is set to the right value automatically, plus the stream is really that size. -- EDIT: Hmm, I'm sleeping again ;P I tried the code and it seems to me that you are indeed short of memory for this action.

      WM. What about weapons of mass-construction?

      1 Reply Last reply
      0
      • S sameerhanda

        ok, good people..i have a following line of code.. using( MemoryStream mStr = new MemoryStream( ) ) { try { mStr.Capacity = totalByteCount ; } } Of course the dude i got inherited this code from is trying to put 141372000 in the memory buffer i.e the capacity. At this point i get the following error Exception of type System.OutOfMemoryException was thrown." } I am at a total loss. Have tried different things...So i throw a hail mary over to the code porject dudes. Thanks for your help Sameer

        J Offline
        J Offline
        Judah Gabriel Himango
        wrote on last edited by
        #3

        If you really need to write 141MB worth into a stream, perhaps the hard drive is a better location (i.e. FileStream) rather tha RAM memory (i.e. MemoryStream).

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: For Christians: The Significance of Yom Teruah The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups