Releasing memory immediately


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Releasing memory immediately

  1. #1
    Join Date
    Dec 2003
    Location
    Italy
    Posts
    250

    Releasing memory immediately

    Hello all,

    Does anybody knows how to destroy (in C#) a non disposable object (an object that has not implemented a dispose method) so the memory used by it could be released immediately?

    I tried setting the object value to null, but it doesn't worked!

    I really appreciate any help.


    Thank you all

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    What code are you using that isn't working?

    Are you getting an error? If so, what?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Dec 2003
    Location
    Italy
    Posts
    250

    Releasing memory immediately

    Hello Hack,

    I have to destroy a Dictionary object (System.Collections.Generic.Dictionary<TKey, TValue>) than contains the Key and as the value, it contains an object.

    The thing is that even if I put null as the value of the object, I can't see the memory used to be released.

    Unfortunately this code is repeated for every record in a datareader, so as the memory is never released, it continues to raise until we get an our of memory error.

    the code is something like this:

    dDataDictionary = new Dictionary<ID, myObject>

    What I tried to do to release the memory was:

    dDataDictionary = null;

    but it doesnt worked....

    Any ideas?

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Try disposing of it
    Code:
    dDataDictionary.Dispose
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  5. #5
    Join Date
    Dec 2003
    Location
    Italy
    Posts
    250

    Releasing memory immediately

    Hi Hack,

    Unfortunately (and amazingly) dDataDictionary doesn't contains a "Dispose" method!!!.

    The available options are:

    Add
    Aggregate<>
    All<>
    Any<>
    AsEnumerable<>
    AsQueryable
    AsQueryable<>
    Average<>
    Cast<>
    Clear
    Comparer
    Concat<>
    Contains<>
    ContainsKey
    ContainsValue
    Count
    Count<>
    DefaultIfEmpty<>
    Distinct<>
    ElementAt<>
    ElementAtOrDefault<>
    Equals
    Except<>
    First<>
    FirstOrDefault<>
    GetEnumerator
    GetHashCode
    GetObjectData
    GetType
    GroupBy<>
    GroupJoin<>
    Intersect<>
    Join<>
    Keys
    Last<>
    LastOrDefault<>
    LongCount<>
    Max<>
    Min<>
    OfType<>
    OnDeserialization
    OrderBy<>
    OrderByDescending<>
    Remove
    Reverse<>
    Select<>
    SelectMany<>
    SequenceEqual<>
    Single<>
    SingleOrDefault<>
    Skip<>
    SkipWhile<>
    Sum<>
    Take<>
    TakeWhile<>
    ToArray<>
    ToDictionary<>
    ToList<>
    ToLookup<>
    ToString
    TryGetValue
    Union<>
    Values
    Where<>


    That's all...

  6. #6
    Join Date
    Dec 2003
    Location
    Italy
    Posts
    250

    Releasing memory immediately

    Hello guys,

    I could release the memory, but I think it's not the better way I could do it, so i would REALLY appreciate your help.

    What I did is setting a null value to each object of the Dictionary object with an specific key, something like this:

    dDataDictionary[kKey].Object1 = null;
    dDataDictionary[kKey].Object2 = null;
    dDataDictionary[kKey].Object3 = null;

    The thing is, after assigning the null values to all the objects within dDataDictionary, I anyway have to "force" the memory to be released, and I did it using:

    GC.Collect();

    This way I can restore the memory to the same levels it was before starting the process that consume the resources (let's say it started with 60Mb, it raided to 180Mb, and afer GC.Collect(), it went back again to 60Mb).

    If I doesn'tuse GC.Collect(), the memory is never released even if I assigned the null value.

    I know it's risky to force GC to do it's job, so I would like to know if anyone has a better solution for this?

    Thank you all.

Similar Threads

  1. Running time: operands in memory versus registers
    By computeruser in forum Architecture and Design
    Replies: 1
    Last Post: 07-08-2008, 03:22 AM
  2. Memory problem with Borland C3.1
    By AZ1699 in forum C++
    Replies: 11
    Last Post: 11-16-2007, 01:23 PM
  3. help memory
    By kathy in forum Java
    Replies: 0
    Last Post: 11-02-2001, 05:22 PM
  4. releasing .dll from memory
    By Yang Du in forum ASP.NET
    Replies: 4
    Last Post: 07-03-2001, 06:26 AM
  5. releasing memory by setting objects to null
    By Max Erixon in forum authorevents.pekowsky
    Replies: 1
    Last Post: 08-18-2000, 12:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center