title: Proper way to release resources with defer in a loop?
body: <p>I need to make SQL queries to database in the loop:</p>
  
  <pre><code>for rows.Next() {
  
     fields, err := db.Query(.....)
     if err != nil {
        // ...
     }
     defer fields.Close()
  
     // do something with `fields`
  
  }
  </code></pre>
  
  <p>What will be better: leave all as is or move <code>defer</code> after loop:</p>
  
  <pre><code>for rows.Next() {
  
     fields, err := db.Query(.....)
     if err != nil {
        // ...
     }
  
     // do something with `fields`
  }
  
  defer fields.Close()
  </code></pre>
  
  <p>Or something else ?</p>