Will using goto cause memory leaks?

前端 未结 10 2216
迷失自我
迷失自我 2021-01-17 11:33

I have a program in which i need to break out of a large bunch of nested for loops. So far, the way most people have been telling me to do it is to use an ugly goto in my co

10条回答
  •  青春惊慌失措
    2021-01-17 12:09

    Will backward goto leak resources ? Or any other potential problems with below code ?

    Reexecute:

            try
            {
                //Setup request
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    
                ....
    
                //Get Response
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    
               if(response != HttpStatus.OK && noOfRetries < 3)
                {
                    noOfRetries++;
                    Thread.Sleep(10 * 1000);
    
    
                    response.Close();
                    goto Reexecute;
                }
                ...
    
                response.Close();
             }
             catch
             {
    
             }
    

提交回复
热议问题