Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda