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

  • Home
  • SEARCH
  • 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 8518485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:59:24+00:00 2026-06-11T05:59:24+00:00

A project that I work on was analyzed by a commercial analysis tool. It

  • 0

A project that I work on was analyzed by a commercial analysis tool. It flagged our implementations of ReaderWriterLockSlim as potential sources of memory leaks because we didn’t call the Dispose() method.

I’ve never seen this method called on this lock: either in code I’ve worked on or code examples I learned from. Should Dispose() be called? What if it’s disposed while a thread still needs it? Is this possible?

Here’s a sample of how we currently use it – no Dispose():

    Public Class Test 
    {

    private ReaderWriterLockSlim _lookupLock = new ReaderWriterLockSlim();

            public IDictionary<int, SomeObject> GetAll()
            {
                _lookupLock.EnterWriteLock();
                try
                {
                    if (X == null || X.Count == 0)
                    {
                        Do Something...;
                    }
                }
                finally
                {
                    _lookupLock.ExitWriteLock();
                }

                return Something...;
            }
}
  • 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-06-11T05:59:25+00:00Added an answer on June 11, 2026 at 5:59 am

    It does need to be disposed.

    Mostly a ReaderWriterLockSlim is used to protect a static resource, so will be a static instance that doesn’t need to be disposed.

    But in your case (one ReaderWriterLockSlim per instance), you would need to make your class IDisposable, and dispose the ReaderWriterLockSlim.

    Or maybe a better alternative is to use an ordinary lock (i.e. Monitor) to protect instance resources rather than a ReaderWriterLockSlim. There’s probably not much performance difference, it makes your code simpler, and it avoids you needing to make your class IDisposable.

    Framework classes like ConcurrentDictionary use ordinary locks.

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

Sidebar

Related Questions

The company I work for is bidding on a project that will require our
I am trying to work on a project that will work on 4 orientations.
I'm working on an iOS project that has to work from iOS4. I have
I work on a project that takes 2-3 minuts to compile. Usually when I
I am going to work on a project that involves Paypal function. My question
I have a large c# project at work that controls a radar jammer. When
I am required to work on a php project that requires the database to
I am working with a C# project that uses the dll, Microsoft.Dynamics.AX.ManagedInterop to work
I'm currently researching a project for the place that I work in. We are
I have multimodule project. Can I make it somehow work that when calling compile

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.