Rightpoint / BentoMap

Map Clustering for Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory leak

zhouhao27 opened this issue · 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?