2

I'm parsing a large number (>1000) of XML files by enumerating a directory, then inserting the parsed data into Yap Database. I tried SWXMLHash and AEXML. Both of them demonstrated similar memory usage, as below:

enter image description here

The plunge comes when the enumeration/insertion finishes. If I read the XML as plain string, it works fine with memory consumption below 160 MB. Using Instruments I'm sure there is no memory leaks and there can't be, as memory is reclaimed at last. So what's going on here?

===== Update:

Eliminating all other possibilities, I came to find out that it ain't because of XML parsing or Yap Database. It's because of the array creation in the XML parsing function.

strongwillow
  • 328
  • 2
  • 13

1 Answers1

1

It's a typical problem caused by autoreleasepool. Manually use autoreleasepool for the following situations:

  1. If you are writing a program that is not based on a UI framework, such as a command-line tool.

  2. If you write a loop that creates many temporary objects. You may use an autorelease pool block inside the loop to dispose of those objects before the next iteration. Using an autorelease pool block in the loop helps to reduce the maximum memory footprint of the application.

  3. If you spawn a secondary thread.

Also check: Is it necessary to use autoreleasepool in a Swift program?

Community
  • 1
  • 1
strongwillow
  • 328
  • 2
  • 13