title: UITableView custom view for section header (memory leaks). What is correct method to make section's header custom view?
body: <p>I am working on an app which has same UI as in "Instagram". I have a feed wall in which user scroll and see new picture added by friends, similar to instagram . Each  UITableViewcell has one picture and its own section Header view. I have achieved this by making sections for each cell. But I am worried about the memoryleak</p>
  
  <p>Here is my code </p>
  
  <pre><code>func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -&gt; UIView? {
  
          let headerView = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, 45))
          headerView.tag = 101
  
          let imageView :UIImageView   = UIImageView(frame: UtilityManager.setFrameWithOutHeight(CGRectMake(22, 5 , 30, 30)))
          imageView.backgroundColor = UIColor.blueColor()
          imageView.tag = 101
          imageView.layer.cornerRadius = 15.0
          imageView.clipsToBounds = true
          imageView.layer.borderWidth = 1
          imageView.layer.borderColor = UIColor.grayColor().CGColor
          headerView.addSubview(imageView)
  
          var label = UILabel(frame: UtilityManager.setFrameWithOutHeight(CGRectMake(50, 5, 320 - 60 , 35)))
          label.textAlignment = NSTextAlignment.Left
          label.backgroundColor = UIColor.clearColor()
          label.textColor = UIColor(red: 1, green: 0.28, blue: 0.27, alpha: 1)
          label.text = "I'am a test label"
          label.font = UIFont(name: Constants.FONT_MEDIUM, size: 12)
          headerView.addSubview(imageView)
          headerView.backgroundColor = UIColor.clearColor()
  
      return headerView
  }
  </code></pre>
  
  <p>Btw I am using Swift. Its so cool isn't it ;) . Let me explain more about this delegate function to make custom section's header. Each time when any of my cell or section comes on screen this delegate method is getting called even if I scroll back to the section whose's headerView has already been allocated. So headerView is being created multiple times for one section while scrolling. But I know It is wrong method there must be something to checking weather headerView has already been created or not. Is there any way to put a check in code if my views does exist in memory then no need to allocate memory again. 
  Somebody please help :). I will appreciate even a small help.</p>