Skip to content

Memory leak #36

@zhouhao27

Description

@zhouhao27

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions