Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #19696 |

    When is the memory used to store zip files released? Does this happen when the method or program ends, or do I need to call something to release the memory?

    Thanks!

    Imported from legacy forums. Posted by Drew (had 3507 views)

    User (Old forums)
    Member
    Post count: 23064

    It depends what you are referring to.

    If you refer to the data of each file that is zipped, the memory used by the compressor to actually build the archive and place the compressed data into it is released as soon as the compression is done.

    If you refer to the local/central header information for each file contained in the archive, it is released when the zip object (ZipArchive) is released, for example when the method where it is declared exits, AND the Garbage Collector has collected the memory associated with the object.

    Imported from legacy forums. Posted by André (had 278 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for the response.

    How do I call the Garbage Collector to collect the memory associated with the object?

    Thanks!

    Imported from legacy forums. Posted by Drew (had 321 views)

    User (Old forums)
    Member
    Post count: 23064

    First, you don’t need to call the Garbage Collector, the .NET framework does it for yourself.

    Second, if you still want to call it, use System.GC.Collect().

    Third, on objects that implement the IDisposable interface (which is NOT the case of ZipArchive), you can call Dispose() on the object, which will free resources associated with the object.

    Fourth, some reading on Garbage Collection may be helpful, to make sure your not creating more problem with calling the GC yourself.

    http://msdn.microsoft.com/msdnmag/issues/1100/gci/

    The following is a discussion on the Compact Framework, but still applies to this discussion :

    http://blogs.msdn.com/stevenpr/archive/2004/07/26/197254.aspx

    Look for the heading “What are the ramifications of calling GC.Collect()?”.

    Imported from legacy forums. Posted by André (had 229 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks, I am going to take a closer look at garbage collection, but I didn’t think that I needed to call it. Thanks for the info!

    Imported from legacy forums. Posted by Drew (had 4725 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.