android 内存(超出最大调用堆栈大小)

android memory (maximum call stack size exceeded)

我遇到内存错误但应用程序没有崩溃,关闭错误后我仍然可以使用它。

我有一个带有主视图的应用程序,每次用户打开另一个页面时都会更改内容:

<Window>
    <ScrollView id='menu'/>
    <View id='content'/>
</Window>

并像这样更新内容:

var data,
update = function(page) {

    data.cleanup();
    data = null;
    data = Alloy.createController('content/'page).getView();
    $.content.add(data);
};

清理函数示例:

$.somepage.cleanup = function() {

    data.button.removeEventListener('click',data.click);
    for(var i in data.slides) data.slides[i].cleanup(); //widgets
    data = args = null;
};

这是我在错误中得到的:

[ERROR] :  TiExceptionHandler: (main) [6643,90546] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [0,90546] - In ti:/titanium.js:0,0
[ERROR] :  TiExceptionHandler: (main) [0,90546] - Message: Uncaught RangeError: Maximum call stack size exceeded
[ERROR] :  TiExceptionHandler: (main) [0,90546] - Source: (function (exports, require, module, __filename, __dirname, Titanium, Ti, glob

唯一在 Appcelerator 控制台中显示很多次的是跟踪级别,它是这样的:

[TRACE] :  TextView: stopSelectionActionMode()

每次移除控制器并添加新控制器时,我都添加了可用内存功能:

[INFO] :   TiApplication: (main) [0,0] checkpoint, app created.
[INFO] :   TiApplication: (main) [162,162] Titanium 5.1.1 (2015/11/24 11:07 e46100b)
[INFO] :   Project built successfully in 3m 18s 95ms
[INFO] :   TiApplication: (main) [596,758] Titanium Javascript runtime: v8
[WARN] :   feature: [BMW]init phonw window
[INFO] :   TiRootActivity: (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
[WARN] :   V8Object: (KrollRuntimeThread) [187,187] Runtime disposed, cannot set property 'userAgent'
[WARN] :   linker: libti.paint.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
[INFO] :   TiRootActivity: (main) [0,0] checkpoint, on root activity resume. activity = pt.winsig.aktionserver.mobile.dev.MobileDevActivity@23fb2b19
[INFO] :   OpenGLRenderer: Initialized EGL, version 1.4
[ERROR] :  E/        : appName=pt.winsig.aktionserver.mobile.dev, acAppName=/system/bin/surfaceflinger
[ERROR] :  E/        : 0
[INFO] :   I/[MALI][Gralloc]: (in-house)open = 0xb5355bb9
[INFO] :   I/[MALI][Gralloc]: (in-house)close = 0xb5355c51
[INFO] :   I/[MALI][Gralloc]: (in-house)alloc = 0xb5355ea1
[INFO] :   I/[MALI][Gralloc]: (in-house)ref = 0xb5355ed1
[INFO] :   art: Background sticky concurrent mark sweep GC freed 2367(218KB) AllocSpace objects, 5(215KB) LOS objects, 3%% free, 22MB/23MB, paused 6.460ms total 18.772ms
[INFO] :   I/[MALI][Gralloc]: (in-house)unref = 0xb5355ef9
[INFO] :   I/[MALI][Gralloc]: gralloc tlcMemOpen recount = 0
[INFO] :   I/[MALI][Gralloc]: gralloc call tlcMemOpen
[ERROR] :  E/[MALI][Gralloc-ERROR]: void gralloc_private_TEEopen():946 tlcMemOpen fail, ret = -65536
[INFO] :   I/[MALI][Gralloc]: gralloc tlcMemOpen recount = 1
[INFO] :   MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
[INFO] :   MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
[INFO] :   MaliEGL: [Mali]max_allowed_dequeued_buffers=3
[INFO] :   APSAnalyticsService: Analytics Service Started
[WARN] :   APSAnalyticsService: Network unavailable, can't send analytics
[INFO] :   APSAnalyticsService: Stopping Analytics Service
[ERROR] :  function DisplayCaps() { [native code] }
[WARN] :   feature: [BMW]init phonw window
[WARN] :   art: Suspending all threads took: 6.111ms
[INFO] :   art: Background partial concurrent mark sweep GC freed 7928(381KB) AllocSpace objects, 4(1484KB) LOS objects, 17%% free, 18MB/22MB, paused 8.403ms total 87.589ms
[WARN] :   TiUIScrollView: (main) [3673,3673] Scroll direction could not be determined based on the provided view properties. Default VERTICAL scroll direction being used. Use the 'scrollType' property to explicitly set the scrolling direction.
[INFO] :   MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
[INFO] :   MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
[INFO] :   MaliEGL: [Mali]max_allowed_dequeued_buffers=3
[INFO] :   Choreographer: Skipped 40 frames!  The application may be doing too much work on its main thread.
[INFO] :   APSAnalyticsService: Analytics Service Started
[INFO] :   APSAnalyticsService: Stopping Analytics Service
[WARN] :   APSAnalyticsService: Network unavailable, can't send analytics
[INFO] :   MEMORY BEFORE: 1298912
[INFO] :   controller check close
[INFO] :   controller check destroy
[INFO] :   controller run destroy
[INFO] :   controller check off
[INFO] :   controller run off
[INFO] :   MEMORY AFTER: 1292560
[INFO] :   MEMORY BEFORE: 509244
[INFO] :   controller check close
[INFO] :   controller check destroy
[INFO] :   controller run destroy
[INFO] :   controller check off
[INFO] :   controller run off
[INFO] :   MEMORY AFTER: 476780
[INFO] :   MEMORY BEFORE: 2706008
[INFO] :   controller check close
[INFO] :   controller check destroy
[INFO] :   controller run destroy
[INFO] :   controller check off
[INFO] :   controller run off
[INFO] :   MEMORY AFTER: 2639976
[ERROR] :  TiExceptionHandler: (main) [9580,89599] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [1,89600] - In ti:/titanium.js:0,0
[ERROR] :  TiExceptionHandler: (main) [0,89600] - Message: Uncaught RangeError: Maximum call stack size exceeded
[ERROR] :  TiExceptionHandler: (main) [0,89600] - Source: (function (exports, require, module, __filename, __dirname, Titanium, Ti, glob
[WARN] :   feature: [BMW]init phonw window
[ERROR] :  V8Exception: Exception occurred at ti:/titanium.js:0: Uncaught RangeError: Maximum call stack size exceeded
[ERROR] :  V8Exception: RangeError: Maximum call stack size exceeded
[INFO] :   MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
[INFO] :   MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
[INFO] :   MaliEGL: [Mali]max_allowed_dequeued_buffers=3
[ERROR] :  libEGL: cache file failed CRC check
[INFO] :   MEMORY BEFORE: 376096
[INFO] :   controller check close
[INFO] :   controller check destroy
[INFO] :   controller run destroy
[INFO] :   controller check off
[INFO] :   controller run off
[INFO] :   MEMORY AFTER: 352352
[INFO] :   MEMORY BEFORE: 1823912
[INFO] :   controller check close
[INFO] :   controller check destroy
[INFO] :   controller run destroy
[INFO] :   controller check off
[INFO] :   controller run off
[INFO] :   MEMORY AFTER: 1554560
[ERROR] :  SQLiteLog: (284) automatic index on documents_lines(obrano)
[INFO] :   WebViewFactory: Loading com.google.android.webview version 47.0.2526.100 (code 252610000)
[INFO] :   cr_LibraryLoader: Time to load native libraries: 2 ms (timestamps 3478-3480)
[INFO] :   cr_LibraryLoader: Expected native library version number "47.0.2526.100", actual native library version number "47.0.2526.100"
[INFO] :   cr_LibraryLoader: Expected native library version number "47.0.2526.100", actual native library version number "47.0.2526.100"
[INFO] :   chromium: [INFO:library_loader_hooks.cc(122)] Chromium logging enabled: level = 0, default verbosity = 0
[INFO] :   cr_BrowserStartup: Initializing chromium process, singleProcess=true
[ERROR] :  SysUtils: ApplicationContext is null in ApplicationStatus
[ERROR] :  E/        : appName=pt.winsig.aktionserver.mobile.dev, acAppName=/system/bin/surfaceflinger
[ERROR] :  E/        : 0
[INFO] :   art: Background partial concurrent mark sweep GC freed 31679(1819KB) AllocSpace objects, 3(48KB) LOS objects, 13%% free, 25MB/29MB, paused 1.739ms total 105.475ms
[WARN] :   cr_media: Requires BLUETOOTH permission
[ERROR] :  WifiManager: mWifiServiceMessenger == null
[INFO] :   Choreographer: Skipped 35 frames!  The application may be doing too much work on its main thread.
[INFO] :   MEMORY BEFORE: 1018608
[INFO] :   controller check close
[INFO] :   controller check destroy
[INFO] :   controller run destroy
[INFO] :   controller check off
[INFO] :   controller run off
[INFO] :   MEMORY AFTER: 710728
[INFO] :   MEMORY BEFORE: 1553480
[INFO] :   controller check close
[INFO] :   controller check destroy
[INFO] :   controller run destroy
[INFO] :   controller check off
[INFO] :   controller run off
[INFO] :   MEMORY AFTER: 1542872
[INFO] :   art: Background partial concurrent mark sweep GC freed 22703(1557KB) AllocSpace objects, 0(0B) LOS objects, 12%% free, 28MB/32MB, paused 1.792ms total 114.905ms
[INFO] :   MEMORY BEFORE: 1439904
[INFO] :   controller check close
[INFO] :   controller check destroy
[INFO] :   controller run destroy
[INFO] :   controller check off
[INFO] :   controller run off
[INFO] :   MEMORY AFTER: 1399504
[INFO] :   art: Background partial concurrent mark sweep GC freed 92433(4MB) AllocSpace objects, 12(756KB) LOS objects, 12%% free, 27MB/31MB, paused 1.681ms total 109.455ms
[INFO] :   MEMORY BEFORE: 597104
[INFO] :   controller check close
[INFO] :   controller check destroy
[INFO] :   controller run destroy
[INFO] :   controller check off
[INFO] :   controller run off
[INFO] :   MEMORY AFTER: 558848
[INFO] :   MEMORY BEFORE: 3212440
[INFO] :   controller check close
[INFO] :   controller check destroy
[INFO] :   controller run destroy
[INFO] :   controller check off
[INFO] :   controller run off
[INFO] :   MEMORY AFTER: 3168808
[ERROR] :  TiExceptionHandler: (main) [3687,145587] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [0,145587] - In ti:/titanium.js:0,0
[ERROR] :  TiExceptionHandler: (main) [0,145587] - Message: Uncaught RangeError: Maximum call stack size exceeded
[ERROR] :  TiExceptionHandler: (main) [0,145587] - Source: (function (exports, require, module, __filename, __dirname, Titanium, Ti, glob
[WARN] :   feature: [BMW]init phonw window
[ERROR] :  V8Exception: Exception occurred at ti:/titanium.js:0: Uncaught RangeError: Maximum call stack size exceeded
[ERROR] :  V8Exception: RangeError: Maximum call stack size exceeded
[INFO] :   MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
[INFO] :   MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
[INFO] :   MaliEGL: [Mali]max_allowed_dequeued_buffers=3

您可以尝试在清理函数中添加这些代码行:

// let Alloy clean up listeners to global collections for data-binding
// always call it since it'll just be empty if there are none
$.destroy();

// remove all event listeners on the controller
$.off();

// remove any listeners you added to global proxies
Ti.Gesture.removeEventListener('orientationchange', onOrientationChange);

// and custom global dispatchers (all at once, via context)
myDispatcher.off(null, null, $);

// in turn, let controllers of required views clean up
$.requiredView.cleanup();

// and close windows of controllers you created, triggering them to clean up as well
someWindow.getView().close();

// this is not needed if someController cleans up well and we have the only reference
// someController = null;

我在这篇文章中找到并使用了这些规则,看看:

http://www.tidev.io/2014/09/18/cleaning-up-alloy-controllers/

超过最大调用堆栈大小与可用内存无关。

勾选here

我怀疑小部件的 cleanup() 功能有问题,或者当您将它放入 for 循环时出现问题。