') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Memory leak with custom style · Issue #47 · mapbox/XcodeClangFormat · GitHub
Skip to content

Memory leak with custom style  #47

Description

@z-aki
  • Setup the Xcode project for XcodeClangFormat for debugging.
  • Build the app and set the style to https://github.com/blender/blender/blob/master/.clang-format
  • Run Extension this time and Xcode launches. Wait for the debugger to attach to the extension.
  • New Xcode command line tool project of C++ language.
  • In the C++ file, select all, paste the code given in the summary. [1] it's total 18 lines.
  • Editor > clang format > format entire file. It will format it correctly.
  • Select all again, paste the code still in your clipboard.
  • Editor > clang format > format entire file. It will fail & the original Xcode instance shows memory increase that settles around 500 MB. The trace appears in the console [2] & UI looks like this [3].
[1] Code to copy
//
// main.cpp
// clang-format-test
//
// Copyright © 2020 ak. All rights reserved.
//
#include <iostream>
#include "main.hh"
int main(int argc, const char *argv[])
{
// Long comment that must be broken down in multiple lines.
// insert code here... insert code here... insert code here... insert code here... insert code here... insert code here...
std::cout << "Hello, World!\n";
return 0;
}
[2] Trace in console
2020-08-03 00:39:49.395275+0530 clang-format[6941:258937] [User Defaults] Couldn't read values in CFPrefsPlistSource<0x60b000012c00> (Domain: XcodeClangFormat, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd
2020-08-03 00:40:00.626852+0530 clang-format[6941:258937] [general] <NSXPCConnection: 0x60d000017bb0> connection from pid 6924: Warning: Exception caught during invocation of received message, dropping incoming message and invalidating the connection.
Exception: *** -[__NSArrayM objectAtIndex:]: index 18 beyond bounds [0 .. 17]
*** -[__NSArrayM objectAtIndex:]: index 18 beyond bounds [0 .. 17]
(
0 CoreFoundation 0x00007fff46876a7d __exceptionPreprocess + 256
1 libobjc.A.dylib 0x00007fff70f4ba17 objc_exception_throw + 48
2 CoreFoundation 0x00007fff468b5a74 -[CFPrefsConfigurationFileSource initWithConfigurationPropertyList:containingPreferences:] + 0
3 CoreFoundation 0x00007fff467b21de -[CFPrefsSearchListSource addNamedVolatileSourceForIdentifier:] + 0
4 clang-format 0x0000000105a5ce7b -[ClangFormatCommand performCommandWithInvocation:completionHandler:] + 9099
5 XcodeKit 0x000000010ae192f4 -[_XCSourceEditorService performCommandInvocation:commandIdentifier:request:reply:] + 494
6 Foundation 0x00007fff48a8da0b __NSXPCCONNECTION_IS_CALLING_OUT_TO_EXPORTED_OBJECT_S4__ + 12
7 Foundation 0x00007fff48a3298f -[NSXPCConnection _decodeAndInvokeMessageWithEvent:flags:] + 2499
8 Foundation 0x00007fff48a31d63 message_handler + 215
9 libxpc.dylib 0x00007fff7294df08 _xpc_connection_call_event_handler + 56
10 libxpc.dylib 0x00007fff7294be9e _xpc_connection_mach_event + 933
11 libdispatch.dylib 0x00007fff726cc6dd _dispatch_client_callout4 + 9
12 libdispatch.dylib 0x00007fff726e10d6 _dispatch_mach_msg_invoke + 436
13 libdispatch.dylib 0x00007fff726d2792 _dispatch_lane_serial_drain + 268
14 libdispatch.dylib 0x00007fff726e1c19 _dispatch_mach_invoke + 481
15 libdispatch.dylib 0x00007fff726d2792 _dispatch_lane_serial_drain + 268
16 libdispatch.dylib 0x00007fff726d33c6 _dispatch_lane_invoke + 433
17 libdispatch.dylib 0x00007fff726db6ed _dispatch_workloop_worker_thread + 598
18 libsystem_pthread.dylib 0x00007fff7290c611 _pthread_wqthread + 421
19 libsystem_pthread.dylib 0x00007fff7290c3fd start_wqthread + 13
)
[3] UI looks like

Screenshot 2020-08-03

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