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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:18:36+00:00 2026-06-03T13:18:36+00:00

I have a collection with WeakReferences to object. The object are loaded dynamically during

  • 0

I have a collection with WeakReferences to object.
The object are loaded dynamically during runtime, and can be collected by GC randomly.

Occasionally, I need to permanently delete an object, this is done with asynchronous DB command.
Meaning – there is a time period between the delete command and the actual commiting of the deletion in the persistency database where the object can be GCed, and then reloaded from the DB.

The easiest way for me to solve this would be to have a ‘Deleted’ flag in each object (already have one), and when performing the deletion action, add a strong reference to the deleted object to the DB Command object, so when the operation completes the strong reference is lost and the object can be released forever.

The question is, is the GC allowed to collect my object with read-ahead? does it apply in this scenario?
Am i guaranteed the that object will not be collected until the DB command is dequeued and processed?

Here is some lower level details:

Dictionary<Int64, WeakReference> mItems;
struct IOCommand
{
    public CommandDetails command;
    public object[] strongReferences;
}
Queue<IOCommand> mIOQueue;
void queueCommand(CommandDetails command, object relatedObject)
{...}

You can see that when queuing a command I pass a related object as a strong reference kept in the queue until it is processed, but as the object are not used the question is can they be optimized away…

Amit.

  • 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-03T13:18:39+00:00Added an answer on June 3, 2026 at 1:18 pm

    As long as your code has a (non-weak) reference to an object it will not be collected.

    So you should be safe, the very fact that a (future) Db Command will use the reference makes sure it will still be be there.

    Just make sure you don’t rely on a WeakReference in this case, that strong reference should have an appropriate lifespan.


    but as the object are not used the question is can they be optimized away…

    No. The way you store them will make sure they exist as long as the command is stored in the Queue, and as long as the queue is reachable of course.

    But note that if they are really not used it shouldn’t even matter…

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

Sidebar

Related Questions

I have two Collection objects, I want to associate each object of these two
I have a collection of the form: map<key, list<object> > I only ever insert
I am developing web application where users have collection of tags. I need to
For example, I have collection with documents, where documents can have field url (but
I have a collection (I'm writing a Weak Dictionary ) and I need to
I have collection of objects. I need to sort it by difficult condition, using
Can you have collection level permissions in MongoDB? Similar to table level permissions in
I have Collection List<Car> . How to compare each item from this collection with
I'm planning to have collection of items stored in a TCollection. Each item will
for example I have collection foo of documents like that: {tag_cloud:[{value:games, count:10}, {value:girls, count:500}]}

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.