BentoMap icon indicating copy to clipboard operation
BentoMap copied to clipboard

Memory leak

Open zhouhao27 opened this issue 6 years ago • 0 comments

Got a lot of memory leak warning in instrument in this code:

public func divide(_ percent: CGFloat, edge: CGRectEdge) -> (MKMapRect, MKMapRect) {
       let amount: Double
       switch edge {
       case .maxXEdge, .minXEdge:
           amount = size.width / 2.0
       case .maxYEdge, .minYEdge:
           amount = size.height / 2.0
       }

       let slice = UnsafeMutablePointer<MKMapRect>.allocate(capacity: 1)
       defer {
           slice.deinitialize()
       }
       let remainder = UnsafeMutablePointer<MKMapRect>.allocate(capacity: 1)
       defer {
           remainder.deinitialize()
       }
       MKMapRectDivide(self, slice, remainder, amount, edge)
       return (slice: slice[0], remainder: remainder[0])
   }

It reminds there are memory leaks for two UnsafeMutablePointer allocation. Any idea?

zhouhao27 avatar Dec 21 '17 09:12 zhouhao27