JSUI memory leak? Update: nope, maybe mcwrapper

Chris Rolfe's icon

I made a test patcher with the JSUI 360 DIAL JSUI file and noticed the memory usage growing steadily. What I'm seeing could be normal JVM memory usage and garbage collection but it seems excessive and the JSUI objects are associated with a crashing patcher.

N.B. the stack trace below is from a more complex patcher with 8 JSUI objects. Later in this stack trace, the mc wrapper object tries to free a corrupt object (possibly a bad list from JSUI? vexpr?).

On my machine, Activity Monitor shows a 1MB leak approximately every 10 s.

Running on a MBP 2015, OS 10.11.6, Max 8.0.6 (64-bit).

Max Patch
Copy patch and select New From Clipboard in Max.

jsui_360dial.js
js 2.68 KB


Crashed Thread: 0 CrBrowserMain Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: EXC_I386_GPFLT
Exception Note: EXC_CORPSE_NOTIFY

Thread 0 Crashed:: CrBrowserMain Dispatch queue: com.apple.main-thread
0 com.cycling74.Max     0x000000010db93696 freeobject + 32
1 com.cycling74.Max     0x000000010db9379e freeobject + 296
2 com.cycling74.Max     0x000000010dc63c23 object_free + 27
3 com.cycling74.Max     0x000000010dc5f207 hashtab_storeflags + 204
4 mc.wrapper~     0x000000012c5ae635 mcwrapper_record + 99
5 mc.wrapper~     0x000000012c5aff3a mcwrapper_client_message_fortarget + 377
6 mc.wrapper~     0x000000012c5ae015 mcwrapper_int + 115
7 com.cycling74.Max     0x000000010dbd89c1 proxy_int + 144
8 com.cycling74.Max     0x000000010dc0b5b6 outlet_int + 1278
9 com.cycling74.Max     0x000000010dbe5823 trigger_iterate + 195
10 com.cycling74.Max     0x000000010dbe5638 trigger_list + 108
11 com.cycling74.Max     0x000000010dc0be80 outlet_list + 587
12 com.cycling74.Max     0x000000010dc0be80 outlet_list + 587
13 com.cycling74.Max     0x000000010db73f2a typedmess_fun + 284
14 com.cycling74.Max     0x000000010dc0be80 outlet_list + 587
15 vexpr     0x00000001290179b7 vexpr_scalarbang + 586
16 com.cycling74.Max     0x000000010dc0b93d outlet_float + 701
17 com.cycling74.Max     0x000000010dc0b37d outlet_int + 709
18 com.cycling74.Max     0x000000010db73ff1 typedmess_fun + 483
19 com.cycling74.Max     0x000000010db74a4b aeval + 1038
20 com.cycling74.Max     0x000000010db44f03 atombuf_eval + 135
21 message     0x0000000121701853 jmessage_atombuf_eval + 631
22 com.cycling74.Max     0x000000010dc0af69 outlet_bang + 1138
23 com.cycling74.Max     0x000000010dbe5855 trigger_iterate + 245
24 com.cycling74.Max     0x000000010dbe5638 trigger_list + 108
25 com.cycling74.Max     0x000000010dc0be80 outlet_list + 587
26 com.cycling74.Max     0x000000010db73f2a typedmess_fun + 284
27 com.cycling74.Max     0x000000010dc0be80 outlet_list + 587
28 com.cycling74.Max     0x000000010db73f2a typedmess_fun + 284
29 com.cycling74.Max     0x000000010dc0be80 outlet_list + 587
30 com.cycling74.Max     0x000000010db73f2a typedmess_fun + 284
31 com.cycling74.Max     0x000000010dc0be80 outlet_list + 587
32 com.cycling74.Max     0x000000010db73f2a typedmess_fun + 284
33 com.cycling74.Max     0x000000010dc0be80 outlet_list + 587
34 com.cycling74.Max     0x000000010db73f2a typedmess_fun + 284
35 com.cycling74.Max     0x000000010dc0be80 outlet_list + 587
36 com.cycling74.Max     0x000000010db73f2a typedmess_fun + 284
37 com.cycling74.Max     0x000000010dc0be80 outlet_list + 587
38 vexpr     0x00000001290179b7 vexpr_scalarbang + 586
39 com.cycling74.Max     0x000000010dc0be80 outlet_list + 587
40 com.cycling74.Max     0x000000010db73f2a typedmess_fun + 284
41 com.cycling74.Max     0x000000010dc0be80 outlet_list + 587
42 vexpr     0x00000001290179b7 vexpr_scalarbang + 586
43 com.cycling74.Max     0x000000010dc0b93d outlet_float + 701
44 com.cycling74.Max     0x000000010dc0b93d outlet_float + 701
45 com.cycling74.Max     0x000000010dbda319 route_float + 236
46 com.cycling74.Max     0x000000010dc0b93d outlet_float + 701
47 com.cycling74.Max     0x000000010dc0b93d outlet_float + 701
48 com.cycling74.Max     0x000000010dc0b93d outlet_float + 701
49 jsui     0x0000000121748e9c jsthis_dooutlet + 258
50 ???     0x000000012d997266 0 + 5059998310

Chris Rolfe's icon

A slight update… I changed the post title.

I was able to isolate the crash from JSUI, so it looks like this is a problem with the mcwrapper.

The stack trace shows a memory error (EXC_BAD_ACCESS) after a mcwrapper call to object_free(). The patcher uses vexpr and iterates a list to setvalue to control mc.line~. I changed to use applyvalues (rather than setvalue) with mcwrapper. So far, no further crashes.

Crashed Thread: 46 Built-in Output

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: EXC_I386_GPFLT
Exception Note: EXC_CORPSE_NOTIFY

Thread 46 Crashed:: Built-in Output
0 com.cycling74.Max     0x000000010c09a696 freeobject + 32
1 com.cycling74.Max     0x000000010c09a79e freeobject + 296
2 com.cycling74.Max     0x000000010c16ac23 object_free + 27
3 com.cycling74.Max     0x000000010c166207 hashtab_storeflags + 204
4 mc.wrapper~     0x000000011fc9e635 mcwrapper_record + 99
5 mc.wrapper~     0x000000011fc9ff3a mcwrapper_client_message_fortarget + 377
6 mc.wrapper~     0x000000011fc9e015 mcwrapper_int + 115
7 com.cycling74.Max     0x000000010c0df9c1 proxy_int + 144
8 com.cycling74.Max     0x000000010c1125b6 outlet_int + 1278
9 com.cycling74.Max     0x000000010c0ec823 trigger_iterate + 195
10 com.cycling74.Max     0x000000010c0ec638 trigger_list + 108
11 com.cycling74.Max     0x000000010c112e80 outlet_list + 587
12 com.cycling74.Max     0x000000010c112e80 outlet_list + 587
13 com.cycling74.Max     0x000000010c07af2a typedmess_fun + 284
14 com.cycling74.Max     0x000000010c112e80 outlet_list + 587
15 vexpr     0x000000011fc629b7 vexpr_scalarbang + 586
16 com.cycling74.Max     0x000000010c11293d outlet_float + 701
17 line     0x000000011fc6d5e3 line_tick + 151
18 com.cycling74.Max     0x000000010c04f82b clock_execute + 56
19 com.cycling74.Max     0x000000010c08ea33 scheduler_run_flags + 346
20 com.cycling74.MaxAudioAPI     0x000000011b569262 plugrunner_serviceclocks + 44
21 com.cycling74.MaxAudioAPI     0x000000011b569e61 plugrunner_servicescheduler + 362
22 com.cycling74.MaxAudioAPI     0x000000011b569cc6 plugrunner_process + 205
23 com.cycling74.MaxAudioAPI     0x000000011b583d2e patchernode_process + 292
24 com.cycling74.MaxAudioAPI     0x000000011b581073 mixerengine_process_fun + 73
25 com.cycling74.Max     0x000000010c106ff2 linklist_funall_imp + 125
26 com.cycling74.MaxAudioAPI     0x000000011b58100c mixerengine_process + 86
27 com.cycling74.MaxAudioAPI     0x000000011b580e3b mixerengine_processiovector + 840
28 com.cycling74.MaxAudioAPI     0x000000011b553698 ad_process + 233
29 ad_coreaudio     0x000000011b64bdd9 adcoreaudio_callback + 317
30 com.cycling74.Max     0x000000010c684072 juce::CoreAudioClasses::AudioIODeviceCombiner::run() + 1394
31 com.cycling74.Max     0x000000010c74996f threadEntryProc + 591
32 libsystem_pthread.dylib     0x00007fff8afc199d _pthread_body + 131
33 libsystem_pthread.dylib     0x00007fff8afc191a _pthread_start + 168
34 libsystem_pthread.dylib     0x00007fff8afbf351 thread_start + 13