Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
abandon awaiting tasks, are they GarbageCollected?

I have case:
Screen1 opens Dialog1, then Dialog1 opens Dialog2, then Dialog2 either returns result to Dialog1 or closes Screen1

Due to technical reasons I want to open each dialog like here (it's pseudo-code, shows idea):

// somewhere in screen1
var dialog1_result = await dialog1.ShowDialogAndAskUser();

// somewhere in dialog1
var dialog2_result = await dialog2.ShowDialogAndAskUser();

But sometimes Dialog2 can close the whole Screen1 and above awaits aren't needed any more.

// somewhere in dialog2
screen1.CloseScreenAndAllDialogs();

Can I leave above awaits on dialog1_result, dialog2_result?
Will GC clean it? (assuming that instances of screen1, dialog1-2 are GC-ed)

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

these tasks are not really abandoned because they are awaited. The question in your case should actually be "What will happen with an uncompleted asynchronous operation?". And the answer is that this code will never be GCed unless the asynchronous method is finished completely (with or without exception). There's not enough info for us to say for sure. Everything depends on what CloseScreenAndAllDialogs does. If ShowDialogAndAskUser async method is never completed explicitly by someone then it will live and wait forever - compiler just cannot finish it for you.

over 4 years ago · Santiago Trujillo Report

0

This is very hard to answer in the general case, because it comes down to is the task still reachable from the thing that is going to say "here's your result"? - and we can't answer that. Is dialog1 still alive, for example? if dialog1 is still reachable and alive, and the task is still incomplete, then dialog1_result will still be reachable and alive - because there is a reference chain in place to allow the result to be set at some future time. The converse is not true, however; the task should not keep the dialog alive (unless someone has used async-state in some unusual way).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!