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 8279903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:28:50+00:00 2026-06-08T09:28:50+00:00

for sure this question has been asked before, but I couldn’t find any thread

  • 0

for sure this question has been asked before, but I couldn’t find any thread about this, so also a link to an answered question would be helpful:

I have a volume class (VoxelVolume) that contains an array of Slices (Slice).

public class VoxelVolume
{
    Slice[] mySlices;

    public VoxelVolume(int noOfSlices)
    {
        mySlices = new Slice[noOfSlices];

        for (int i = 0; i < mySlices.Length; i++)
        {
            mySlices[i] = new Slice(this);
        }
    }
}

The volume knows the Slices and the Slices know the Volume:

public class Slice
{
    public VoxelVolume Volume
    {
        get;
        private set;
    }

    public Slice(VoxelVolume aVolume)
    {
        Volume = aVolume;
    }
}

The problem is that the volume never gets garbage collected since there is a mutual object referencing. For that reason I implemented the reference from the slice to the volume as WeakReference:

public class Slice
{
    WeakReference myVolume;

    VoxelVolume Volume
    {
        get
        {
            return (VoxelVolume)myVolume.Target;
        }
    }

    public Slice(VoxelVolume aVolume)
    {
        myVolume = new WeakReference(aVolume);
    }
}

Now the garbage collection works, but with the effort of an additional WeakReference. Since I can have many thousands of slices the effort of WeakReferences is very high.

Edit: First it didn’t show up, but since we are using a lot of memory there was a “memory leak”. Therefore we had a look into the referenced and available objects using JetBrains dotTrace. There we have seen that a lot of objects are available although they are not used anymore. As I said before using the WeakReference solved the problem.

The question is, how the TreeView solves these problems, since the TreeNode also has a knowledge of the TreeView.

Do you know a suitable solution to this?

Thank you
Martin

  • 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-08T09:28:52+00:00Added an answer on June 8, 2026 at 9:28 am

    The problem is that the volume never gets garbage collected since there is a mutual object referencing.

    That’s only going to be a problem if something has access to either the Slice or the VoxelVolume. When you no longer have references to either object, they will both be eligible for garbage collection. Cycles in objects aren’t a problem in .NET, as it doesn’t use reference counting.

    Of course, you do need to make sure you don’t have a reference to either the Slice or the VoxelVolume from any GC roots. You haven’t really given us enough context to know what’s going on here.

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

Sidebar

Related Questions

I'm not sure if this question has been asked before but are there any
I'm sure this question has been asked before, but I'm too frustrated to find
I'm sure this question has been asked before, but I can't seem to find
Well, I'm sure this question has been asked before but I'm yet to find
sorry if this question has been asked before, I searched but wasn't sure on
I'm not sure if this question has been asked before but what are the
I'm not sure if this question has been asked before, but I can't seem
I'm sure that this question has been asked before but I've been unable to
This has probably been asked before but I couldn't find the answer to my
I'm sorry if this question has been asked before, but I'm not even sure

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.