Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3978786
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:05:25+00:00 2026-05-20T05:05:25+00:00

I am using a 3rd-party object I didn’t create that over time consumes a

  • 0

I am using a 3rd-party object I didn’t create that over time consumes a lot of resources. This object shouldn’t in any way contain a state, it simply performs a calculation. Despite this fact, everytime I call a specific function of this object a little more memory is consumed. A few hours later, and my program is sitting at gigabytes of allocated memory.

The object was origionaly initialized as a static member of my Program class in my command-line application. I have found that if I wrap my entire program in an class, and reinitialize it every now and again, the older (and bloated) object is unallocated by GC and a new smaller object replaces it.

My issue is this method is quite clumsy and ruins the flow of my Program.

Is there any other way you can dispose of an object? I am lead to believe GC.Collect() will only dispose unreachable code. Is there anyway I can make an object ‘unreachable’?

Edit: As requested, the code:

static ILexicon lexicon = new Lexicon();

…

lexicon.LoadDataFromFile(@"lexicon.dat", null);

…

    byte similarityScore(string w1, string w2, PartOfSpeech pos, SimilarityMeasure measure)
    {
        if (w1 == w2)
            return 255;
        if (pos != PartOfSpeech.Noun && pos != PartOfSpeech.Verb)
            return 0;

        IList<ILemma> w1_lemmas = lexicon.FindSenses(w1, pos);
        IList<ILemma> w2_lemmas = lexicon.FindSenses(w2, pos);
        byte result;
        byte score = 0;

        foreach (ILemma w1_lemma in w1_lemmas)
        {
            foreach (ILemma w2_lemma in w2_lemmas)
            {
                result = (byte) (w1_lemma.GetSimilarity(w2_lemma, measure) * 255);
                if (result > score)
                    score = result;
            }
        }

        return score;
    }

As similarityScore is called, more memory is allocated to a private member of lexicon. It does not implement IDisposable and there are no obvious functions to clear the memory. The library is based on WordNet, and uses an algorithm to find path lengths in the hypernym tree to calculate the similarity of two words. Unless there is caching, I can’t see why it would need to store any memory. What is for sure, is I can’t change it. I’m almost certain there is nothing wrong with my code. I just need to dispose of lexicon when it gets too large (N.B. it takes a second or two to load the lexicon from file to memory)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:05:26+00:00Added an answer on May 20, 2026 at 5:05 am

    If the object doesn’t implement IDisposable and you want to push it out of scope you can set all references to it to null and then the force garbage collection with GC.Collect().

    GC.Collect() is very expensive. If you’re going to have to do this frequently, you might want to consider contacting the vendor.

    Find out:

    1. If you are using their library correctly, or is there something you’re doing wrong that’s causing the memory leak.
    2. If their library is leaking memory even when used as intended, can they fix the leak?

    Additional note: If the 3rd party library is native and you’re having to use interop, you can use Marshal.ReleaseComObject to free unmanaged memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using an object from a 3rd party API that has a property of
I'm using a 3rd party library that uses a lot of threads. I've just
I'm using a 3rd party DLL written in unmanaged C++ that controls some hardware
This is driving me nuts. I am using some 3rd-party code in a Windows
I'm new to threads. I'm using a 3rd party library that uses threads which
We have a 3rd-party app that wants to call a stored proc using SQL
I am using a 3rd-party rotator object, which is providing a smooth, random rotation
I'm using a 3rd party lib to do some work. I'm passing an object
I have a standalone (3rd party) app that I'm trying to launch using a
I have the following code that downloads an object from a 3rd party and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.