My app working with Geojson
file. I use MapBox SDK to add MGLPolyline
to map. But the problem is my file too large, so that the app crash and got the e
One thing I have learnt from creating memory intensive apps is that you have to use autoreleasepool
every time you create variables inside loops, if these loops are long
Review all your code and transform things like
func loopALot() {
for _ in 0 ..< 5000 {
let image = NSImage(contentsOfFile: filename)
}
}
into
func loopALot() {
for _ in 0 ..< 5000 {
autoreleasepool {
let image = NSImage(contentsOfFile: filename)
}
}
}
Review all kinds of loops for
, while
, etc.
This will force of iOS to release the variable and its correspondent memory usage at the end of every turn of the loop, instead of holding the variable and its memory usage until the function ends. That will reduce dramatically your memory usage.