What is crashing here?

Got a crash log from a customer:

Thread 11 Crashed:
0 com.xojo.XojoFramework 0x0171077f 0x16ba000 + 354175
1 com.xojo.XojoFramework 0x017107f3 0x16ba000 + 354291
2 com.xojo.XojoFramework 0x0171ba21 0x16ba000 + 399905
3 com.xojo.XojoFramework 0x01713bd2 0x16ba000 + 367570
4 com.xojo.XojoFramework 0x01719cf5 StringReplaceAll + 53
5 com.mothsoftware.mailarchiverx 0x0022e08a REALbasic.ReplaceAll%s%sss + 79
6 com.mothsoftware.mailarchiverx 0x011f1779 AttachmentsAndMimeCleaner.execute%o%o + 2534
7 com.mothsoftware.mailarchiverx 0x00d07702 MailParser.parse%i4%o + 17474
8 com.mothsoftware.mailarchiverx 0x00c9f00e ArchiveThread.DoWork%%o + 3673
9 com.mothsoftware.mailarchiverx 0x00c9e155 ArchiveThread.Event_Run%%o + 56
10 com.xojo.XojoFramework 0x017dc8ba 0x16ba000 + 1190074
11 libsystem_pthread.dylib 0x98db15fb _pthread_body + 144
12 libsystem_pthread.dylib 0x98db1485 _pthread_start + 130
13 libsystem_pthread.dylib 0x98db6cf2 thread_start + 34

which is typical for memory problems. I then made him a version, which looks at available and free memory:

2015-11-02, 11:23:09 Total physical Memory: 25165824 KB
2015-11-02, 11:23:09 Physical Memory used by MAX: 195712 KB
2015-11-02, 11:23:09 Free physical Memory: 1556384 KB
2015-11-02, 11:23:09 Total virtual Memory: 14977652 KB
2015-11-02, 11:23:09 Virtual Memory used by MAX: 1157396 KB
2015-11-02, 11:23:09 Free virtual Memory: 1556384 KB
2015-11-02, 11:23:09 Subject: Plan

and immediately after the app crashes. So this doesn’t look like a memory problem. And the crash seems to happen for the same mail. The new version also replaces the ReplaceAll function with a very simple self-made function.

Original:

theMailFields.MessageRawData = ReplaceAll(theMailFields.MessageRawData, Encodings.ASCII.Chr(9), "")

Replacement:

dim theResult(-1) as string for currentChar as Integer = 0 to Len(theMailFields.MessageRawData) - 1 dim theChar as String = Mid(theMailFields.MessageRawData, currentChar, 1) if theChar <> Chr(9) then theResult.Append theChar next theMailFields.MessageRawData = Join(theResult, "")

And now the customer gets the following crash:

Thread 12 Crashed:
0 libsystem_kernel.dylib 0x98b44952 __pthread_kill + 10
1 libsystem_pthread.dylib 0x9525d167 pthread_kill + 101
2 libsystem_c.dylib 0x94cd229c abort + 155
3 libc++abi.dylib 0x921e46c9 abort_message + 169
4 libc++abi.dylib 0x9220547d default_terminate_handler() + 264
5 libc++abi.dylib 0x92202c30 std::__terminate(void (*)()) + 14
6 libc++abi.dylib 0x9220264b __cxa_throw + 116
7 libc++.1.dylib 0x90d5cb66 operator new(unsigned long) + 102
8 com.xojo.XojoFramework 0x017b8699 0x16bc000 + 1033881
9 com.mothsoftware.mailarchiverx 0x011ffb38 AttachmentsAndMimeCleaner.MyRemoveTab%%o + 893
10 com.mothsoftware.mailarchiverx 0x011f39ef AttachmentsAndMimeCleaner.execute%o%o + 2248
11 com.mothsoftware.mailarchiverx 0x00d0863b MailParser.parse%i4%o + 17954
12 com.mothsoftware.mailarchiverx 0x00c9fd67 ArchiveThread.DoWork%%o + 3673
13 com.mothsoftware.mailarchiverx 0x00c9eeae ArchiveThread.Event_Run%%o + 56
14 com.xojo.XojoFramework 0x017de8ba 0x16bc000 + 1190074
15 libsystem_pthread.dylib 0x9525c5fb _pthread_body + 144
16 libsystem_pthread.dylib 0x9525c485 _pthread_start + 130
17 libsystem_pthread.dylib 0x95261cf2 thread_start + 34

Does anyone have an idea what is happening here?

Xojo 2014r2, Mac OS 10.9.5.

7 libc++.1.dylib 0x90d5cb66 operator new(unsigned long) + 102 <<<<<<<<<<
8 com.xojo.XojoFramework 0x017b8699 0x16bc000 + 1033881
9 com.mothsoftware.mailarchiverx 0x011ffb38 AttachmentsAndMimeCleaner.MyRemoveTab%%o + 893

line 7 tells me this is out of memory

Thanks for the fast reply, Norman.

The memory used by my app is about 200 MB immediately before the crash. There is also 1.5 GB free memory. How can a memory problem occur so fast? The crashing code is the beginning of my parsing algorithm, even before I split the mail into pieces. This usually makes the memory problems. I’ve seen mails that are 300 MB large. In this version only mails up to 50 MB are allowed to prohibit crashes.

If it needs a really huge contiguous chunk and its not available

Have a peek in AttachmentsAndMimeCleaner.MyRemoveTab
Maybe it ends up with a ton of temporaries that each take up a lo lot of space ?

Still scratching my head… I posted the MyRemoveTab above. There IS no more code. And the original code just removes the tabs.

How do I find out if I have a contiguous chunk of memory available or not?