Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Weird! MEX crash followed by "out of memory" after restarting matlab

Subject: Weird! MEX crash followed by "out of memory" after restarting matlab

From: wei feng

Date: 21 Feb, 2009 17:50:19

Message: 1 of 8

Hi all,

I have a mex function which caused a crash after running my program almost all the way to the end. Fine, I see this all the time. But then after I closed matlab and restarted it, and ran the program again, it almost instantly popped an error saying "Out of memory". I looked at my work space and there was not much in there at all. How could it be out of memory? So I closed matlab again and restarted it again, the same thing happened. It seems like the crash in the beginning made some permanent damage.

Then I went to home and run the code again. My program ran almost all the way and then the crash came, just like what I saw in my office. Then I restarted matlab and tried again, the same thing happened.

I did try to search for an answer but failed. The following is the crash report before this out of memory behavior. I apologize if it is too long. In fact, there was another crash report right after this (they happened at the same time). It looks like a repetition of the following message except a few lines different in the beginning. For space's sake, I am not posting the second one.

Please help.

==================
------------------------------------------------------------------------
             Assertion detected at Fri Feb 20 16:28:49 2009
------------------------------------------------------------------------

Assertion failed: Forced Assertion at line 714 of file ".\memmgr\mem32aligned.cpp".
Corrupted memory block found


Configuration:
  MATLAB Version: 7.5.0.342 (R2007b)
  MATLAB License: 194316
  Operating System: Microsoft Windows XP
  Window System: Version 5.1 (Build 2600: Service Pack 2)
  Processor ID: x86 Family 15 Model 4 Stepping 3, GenuineIntel
  Virtual Machine: Java 1.6.0 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode
  Default Charset: windows-1252

Stack Trace:
  [0] mcr.dll:_mnSignalHandler(0xffffffff, 0, 0, 0x39e9100f) + 385 bytes
  [1] mcr.dll:void __cdecl ThrowAssertion(void)(0x00f35048, 0x18dd0000, 0x18ddfb78 "?rI?-?G??", 0x65737341) + 167 bytes
  [2] mcr.dll:_MATLABAssertFcn(0x7abec038 ": Forced Assertion", 0x7abec700 ".\memmgr\mem32aligned.cpp", 714, 0x7abecaac "Corrupted memory block found") + 124 bytes
  [3] libut.dll:_mw_malloc32(8, 0, 0x18534480, 0x00cec0b0 "???") + 289 bytes
  [4] libut.dll:_mw_calloc32(8, 1, 0, 0x00cec0dc) + 38 bytes
  [5] libut.dll:_utCalloc(8, 1, 0x3e594e40, 0x1757f9d8) + 88 bytes
  [6] udd.dll:public: __thiscall UDListenerList::UDListenerList(class UDListenerManager *,class UDEventSource const *,class UDEventInfo const *)(0x1757f9d8, 0x1832b1a4 ",Bxx", 0x0152f140, 0x3e594f90) + 86 bytes
  [7] udd.dll:public: void __thiscall UDListenerManager::addListener(class UDListener *,class UDEventSource const *,class UDEventInfo const *)(0x1701aec0, 0x1832b1a4 ",Bxx", 0x18534480, 0x1701aec0) + 105 bytes
  [8] udd.dll:public: void __thiscall UDListenerManagerHost::addListener(class UDListener *,class UDEventSource const *,class UDEventInfo const *)(0x1701aec0, 0x1832b1a4 ",Bxx", 0x0152f140, 0x39ccbcd7) + 50 bytes
  [9] hg.dll:_addHGListenerDestroy(0x1832b1a0 "4Bxx,Bxx", 0x78731520, 0, 0x12a23660) + 132 bytes
  [10] hg.dll:_InitGObject(0x12a23660, 0x153de8fc, 0x7870c767, 18) + 1221 bytes
  [11] hg.dll:_create_GObject(18, 0x39ccbf4f, 0x153de8fc, 6) + 46 bytes
  [12] hg.dll:double __cdecl ConvertStructToHandle(struct mxArray_tag * *,struct GObject_tag *,struct HandleTable_tag *,struct HandleTable_tag *,bool)(0x153de8fc, 0x12a21fa0, 0x15012e20, 0x15018910) + 344 bytes
  [13] hg.dll:double __cdecl ConvertStructToHandle(struct mxArray_tag * *,struct GObject_tag *,struct HandleTable_tag *,struct HandleTable_tag *,bool)(0x12b79e2c, 0x12a218a0, 0x15012e20, 0x15018910) + 1103 bytes
  [14] hg.dll:_hgStruct2NHandles(0x18ddfd00, 0x00cec510, 1, 1) + 488 bytes
  [15] hg.dll:void __cdecl SetFigureMenuBar(double,bool)(0, 0x40240000, 0x3e1de401, 0x1832aca0) + 164 bytes
  [16] hg.dll:void __cdecl figureMenuBarPostSet(class UDInterface *,struct NDMdata_tag *,void *)(0x1832aca0, 0x16658501 "r@UmyTraceList@@V?$allocator@Umy..", 0x00cec578, 0x12a218a0) + 94 bytes
  [17] hg.dll:void __cdecl callFigurePostSetListeners(class UDInterface *,struct NDMdata_tag *)(0x18534240, 1, 0x18537120, 0x18534240) + 514 bytes
  [18] hg.dll:struct WinRec_tag * __cdecl really_create_figure_window(struct GObject_tag *,struct WinRec_tag *,struct Color_tag *,class UDInterface *,struct NDMdata_tag *)(0x18537120, 0x1832aca0, 0x166585e0, 0) + 252 bytes
  [19] hg.dll:_displayMgrAddFigure(0x1832aca0, 0x01514550 "?Bxx", 0x00cec628 "H??", 0x7873ddee) + 402 bytes
  [20] hg.dll:void __cdecl displayChildAdd(class UDInterface *,void *,void *)(0x1832aca0, 0, 0, 0x7a646901) + 45 bytes
  [21] hg.dll:public: virtual bool __thiscall HGChildListener::execute(class UDEvent *)(0x00cec69c, 0x78784234, 0x1832aca0, 0x02b696e4 ",Bxx") + 62 bytes
  [22] udd.dll:public: bool __thiscall UDListenerList::execute(class UDEvent *)(0x00cec69c, 0x00cec6c4 "???", 0x7a670080, 0x0152f130) + 89 bytes
  [23] udd.dll:public: virtual void __thiscall UDListenerManagerHost::notifyEvent(class UDDatabaseClient *,class UDEventSource const *,class UDEventInfo const *,class UDEvent *)(0x0152f130, 0x02b696e4 ",Bxx", 0x01514570, 0x00cec69c) + 54 bytes
  [24] udd.dll:private: void __thiscall UDInterface::notifyChildAddedAndParentChanged(class UDInterface *)(0, 0x3e594864, 0x02b696e0 "4Bxx,Bxx", 0x1832aca0) + 176 bytes
  [25] udd.dll:public: void __thiscall UDInterface::addRight(class UDInterface *)(0x1832aca0, 0x3e5949b8, 0x12a218a0, 0x02260720) + 405 bytes
  [26] udd.dll:public: void __thiscall UDInterface::addFirstBelow(class UDInterface *)(0x02b696e0 "4Bxx,Bxx", 0x00cec74c "d??", 0x7872fd89, 0x1832aca0) + 134 bytes
  [27] udd.dll:_udiSetParent(0x1832aca0, 0x02b696e0 "4Bxx,Bxx", 0x7872fed0, 0x787b1a50) + 19 bytes
  [28] hg.dll:_sgo_parent(0x12a218a0, 0x02260720, 0, 0) + 153 bytes
  [29] hg.dll:_sgo_parent_handle(0x12a218a0, 0, 0, 0x787b1a50) + 28 bytes
  [30] hg.dll:_callDoubleSetFcnUDDOptional(0x787b1a50, 0x12a218a0, 0, 0) + 114 bytes
  [31] hg.dll:public: virtual void __thiscall HGPropInfo::setValueE(class UDDatabaseClient *,class UDInterface *,void *,class UDErrorStatus *)(0x60051668 "XWhz", 0x1832aca0, 0x00cec8d4, 0x00cec8cc "?Xhz") + 206 bytes
  [32] udd.dll:public: void __thiscall UDInterface::setE(class UDDatabaseClient *,class UDPropInfo *,void *,class UDErrorStatus *)(0x60051668 "XWhz", 0x017843ac, 0x0152f1c0, 0x00cec8cc "?Xhz") + 626 bytes
  [33] udd.dll:_udiSet(0x1832aca0, 0x0152f1a0, 0x00cec8d4, 0) + 42 bytes
  [34] hg.dll:_goSetUDDDoubleProp(0x1832aca0, 0, 0, 0x0152f1a0) + 137 bytes
  [35] hg.dll:_callDoubleSetFcnUDDOptional(0x787b1a50, 0x12a218a0, 0, 0) + 41 bytes
  [36] hg.dll:_Matrix_to_parent_handle_set_check_fcn(0x14ce57e0, 0x12a218a0, 0x787b1a50, 0) + 95 bytes
  [37] hg.dll:enum SetStatus __cdecl HG_SetSwitchYard(struct GObject_tag *,struct GO_PropID_tag *,struct mxArray_tag *)(0x12a218a0, 0x7872e1f0, 0x14ce57e0, 0x79022460) + 679 bytes
  [38] hg.dll:_hgDoPostCreationActions(0x00cecad0, 1, 0, 0x00cecc64) + 1230 bytes
  [39] hg.dll:_HandleCreationStuff(0x00cecad0, 1, 0, 0x00cecc64) + 42 bytes
  [40] hg.dll:struct GObject_tag * __cdecl create_new_figure(double,int,struct mxArray_tag * *)(0, 0, 0, 0x00cecc64) + 162 bytes
  [41] hg.dll:_hgFigure(0, 0x00cecc04, 0, 0x00cecc64) + 198 bytes
  [42] hgbuiltins.dll:void __cdecl createFigure(int,struct mxArray_tag * * const,int,struct mxArray_tag * * const)(0, 0x00cecc04, 0, 0x00cecc64) + 56 bytes
  [43] m_dispatcher.dll:public: virtual void __thiscall Mfh_builtin::dispatch_mf(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00cecc04, 0, 0x00cecc64) + 112 bytes
  [44] m_dispatcher.dll:public: virtual void __thiscall Mfh_MATLAB_fn::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00cecc04, 0, 0x00cecc64) + 163 bytes
  [45] m_interpreter.dll:__catch$?inDispatchFromStack@@YAHHPBDHH@Z$0(207, 0x151b3bd0 "figure", 0, 0) + 744 bytes
  [46] m_interpreter.dll:enum opcodes __cdecl inDispatchCall(char const *,int,int,int,int *,int *)(0x151b3bd0 "figure", 207, 0, 0) + 156 bytes
  [47] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *,int *)(1, 2730, 57, 0) + 2614 bytes
  [48] m_interpreter.dll:int __cdecl protected_inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 2730, 43, 0) + 87 bytes
  [49] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 2730, 43, 0) + 274 bytes
  [50] m_interpreter.dll:int __cdecl inExecuteMFunctionOrScript(class Mfh_mp *,bool)(0x16429320, 0x15072a00 "WindowPostChangeEvent", 0x4d2189ea, 0xffffffff) + 916 bytes
  [51] m_interpreter.dll:void __cdecl inRunMfile(int,struct mxArray_tag * *,int,struct mxArray_tag * *,class Mfh_mp *,struct inWorkSpace_tag *)(2, 0x00ced244, 5, 0x00ced2a4) + 673 bytes
  [52] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(struct _mdUnknown_workspace *,int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 2, 0x00ced244, 5) + 29 bytes
  [53] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(2, 0x00ced244, 5, 0x00ced2a4) + 28 bytes
  [54] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(2, 0x00ced244, 5, 0x00ced2a4) + 203 bytes
  [55] m_interpreter.dll:__catch$?inDispatchFromStack@@YAHHPBDHH@Z$0(926, 0x12647a3c "cir_lm_one_map_optimization", 2, 5) + 744 bytes
  [56] m_interpreter.dll:enum opcodes __cdecl inDispatchCall(char const *,int,int,int,int *,int *)(0x12647a3c "cir_lm_one_map_optimization", 926, 2, 5) + 156 bytes
  [57] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *,int *)(1, 1867, 98, 0) + 2614 bytes
  [58] m_interpreter.dll:int __cdecl protected_inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 1867, 41, 0) + 87 bytes
  [59] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 1867, 41, 0) + 274 bytes
  [60] m_interpreter.dll:int __cdecl inExecuteMFunctionOrScript(class Mfh_mp *,bool)(0x16429160, 0x14c4ac00, 0x4d218faa, 0xffffffff) + 916 bytes
  [61] m_interpreter.dll:void __cdecl inRunMfile(int,struct mxArray_tag * *,int,struct mxArray_tag * *,class Mfh_mp *,struct inWorkSpace_tag *)(3, 0x00ced884, 5, 0x00ced8e4) + 673 bytes
  [62] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(struct _mdUnknown_workspace *,int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 3, 0x00ced884, 5) + 29 bytes
  [63] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(3, 0x00ced884, 5, 0x00ced8e4) + 28 bytes
  [64] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(3, 0x00ced884, 5, 0x00ced8e4) + 203 bytes
  [65] m_interpreter.dll:__catch$?inDispatchFromStack@@YAHHPBDHH@Z$0(874, 0x12b4ba2c "cir_lm_optimization", 3, 5) + 744 bytes
  [66] m_interpreter.dll:enum opcodes __cdecl inDispatchCall(char const *,int,int,int,int *,int *)(0x12b4ba2c "cir_lm_optimization", 874, 3, 5) + 156 bytes
  [67] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *,int *)(1, 2464, 185, 0) + 2614 bytes
  [68] m_interpreter.dll:int __cdecl protected_inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 2464, 30, 0) + 87 bytes
  [69] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 2464, 30, 0) + 274 bytes
  [70] m_interpreter.dll:int __cdecl inExecuteMFunctionOrScript(class Mfh_mp *,bool)(0x164286e0, 0x14c4b500, 0x4d21866a, 0xffffffff) + 916 bytes
  [71] m_interpreter.dll:void __cdecl inRunMfile(int,struct mxArray_tag * *,int,struct mxArray_tag * *,class Mfh_mp *,struct inWorkSpace_tag *)(5, 0x00cedec4, 3, 0x00cedf24) + 673 bytes
  [72] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(struct _mdUnknown_workspace *,int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 5, 0x00cedec4, 3) + 29 bytes
  [73] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(5, 0x00cedec4, 3, 0x00cedf24) + 28 bytes
  [74] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(5, 0x00cedec4, 3, 0x00cedf24) + 203 bytes
  [75] m_interpreter.dll:__catch$?inDispatchFromStack@@YAHHPBDHH@Z$0(867, 0x01575836 "cir_image_reg", 5, 3) + 744 bytes
  [76] m_interpreter.dll:_inCallFcnFromReference(0x4d21b886, 0xffffffff, 0x01514a1c, 0) + 166 bytes
  [77] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *,int *)(1, 0, 103, 0) + 4760 bytes
  [78] m_interpreter.dll:int __cdecl protected_inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 0, 6, 0) + 87 bytes
  [79] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 0, 6, 0) + 274 bytes
  [80] m_interpreter.dll:int __cdecl inExecuteMFunctionOrScript(class Mfh_mp *,bool)(0x16428520, 0x16407401, 0x4d21bc6a, 0xffffffff) + 916 bytes
  [81] m_interpreter.dll:void __cdecl inRunMfile(int,struct mxArray_tag * *,int,struct mxArray_tag * *,class Mfh_mp *,struct inWorkSpace_tag *)(0, 0x00cee4c4, 0, 0x00cee524) + 673 bytes
  [82] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(struct _mdUnknown_workspace *,int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0, 0x00cee4c4, 0) + 29 bytes
  [83] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00cee4c4, 0, 0x00cee524) + 28 bytes
  [84] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00cee4c4, 0, 0x00cee524) + 203 bytes
  [85] m_interpreter.dll:__catch$?inDispatchFromStack@@YAHHPBDHH@Z$0(771, 0x015eaf24 "test_cir_image_reg", 0, 0) + 744 bytes
  [86] m_interpreter.dll:enum opcodes __cdecl inDispatchCall(char const *,int,int,int,int *,int *)(0x015eaf24 "test_cir_image_reg", 771, 0, 0) + 156 bytes
  [87] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *,int *)(2, 0, 0, 0) + 2739 bytes
  [88] m_interpreter.dll:int __cdecl protected_inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(2, 0, 0, 0) + 87 bytes
  [89] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(2, 0, 0, 0) + 274 bytes
  [90] m_interpreter.dll:_inInterPcode(2, 0x4d21b092, 0, 0x12374420 "test_cir_image_reg\n") + 162 bytes
  [91] m_interpreter.dll:enum inExecutionStatus __cdecl in_local_call_eval_function(int *,struct _pcodeheader *,int *,struct mxArray_tag * * const,enum inDebugCheck,bool)(0x00cef2bc, 0x00cef32c, 0x00cef358, 2) + 152 bytes
  [92] m_interpreter.dll:enum inExecutionStatus __cdecl inEvalStringWithIsVarFcn(struct _memory_context *,char const *,enum EvalType,int,struct mxArray_tag * * const,enum inDebugCheck,struct _pcodeheader *,int *,bool (__cdecl*)(void *,char const *),void *,bool)(0x7ac2177c, 0x12374420 "test_cir_image_reg\n", 0, 0) + 2454 bytes
  [93] m_interpreter.dll:enum inExecutionStatus __cdecl inEvalCmdWithLocalReturnandtype(char const *,int *,enum inDebugCheck,bool)(0x12374420 "test_cir_image_reg\n", 0, 2, 0) + 107 bytes
  [94] m_interpreter.dll:_inEvalCmdNoEnd(0x12374420 "test_cir_image_reg\n", 0, 0x3e0102c8, 0x7ab9e7f0) + 20 bytes
  [95] bridge.dll:enum inExecutionStatus __cdecl ThrowSignal(char const *)(0x12374420 "test_cir_image_reg\n", 0x3e010584, 0x014e4418, 0x014e43b8) + 77 bytes
  [96] bridge.dll:__catch$_mnParser$0(0x39e924ff, 0x014e43b8, 0x014e43b8, 0) + 292 bytes
  [97] mcr.dll:public: void __thiscall mcrInstance::mnParser(void)(0x39b2fda7, 0x004043f0, 402246, 0) + 62 bytes
  [98] MATLAB.exe:0x00401414(4194304, 0, 402246, 10)
  [99] MATLAB.exe:0x00401733(0, 0, 0x7ffd9000, 0x8054a6ed)
  [100] kernel32.dll:0x7c816fd7(0x00401910, 0, 0x78746341, 32)

Please follow these steps to report this problem to The MathWorks so we
have the best chance of correcting it:

The next time MATLAB is launched under typical usage, a dialog box will
open to help you send the error log to The MathWorks. Alternatively, you
can send an e-mail to segv@mathworks.com with the following file attached:
    C:\DOCUME~1\fengwe1\LOCALS~1\Temp\matlab_crash_dump.3716

If the problem is reproducible, please submit a Service Request via:
    http://www.mathworks.com/support/contact_us/ts/help_request_1.html

A technical support engineer might contact you with further information.

Thank you for your help. Save your workspace and restart MATLAB.

??? Error using ==> figure
Error using ==> arbitrary_position_grad_sparse
size of fwd adaptive map is not equal to size of deformation.

Error in ==> <a href="error:C:\Documents and Settings\fengwe1\My Documents\research\CIR\cir_code\trunk\core\cir_lm_one_map_optimization.m,57,0">cir_lm_one_map_optimization at 57</a>
        figure;

Error in ==> <a href="error:C:\Documents and Settings\fengwe1\My Documents\research\CIR\cir_code\trunk\core\cir_lm_optimization.m,98,0">cir_lm_optimization at 98</a>
        [motion_field_new, evol_nodes{end+1}] = ...

Error in ==> <a href="error:C:\Documents and Settings\fengwe1\My Documents\research\CIR\cir_code\trunk\core\cir_image_reg.m,185,0">cir_image_reg at 185</a>
                [motion_fwd, motion_bwd, evol] = ...

Error in ==> <a href="error:C:\Documents and Settings\fengwe1\My Documents\research\CIR\cir_code\trunk\tools\test_cir_image_reg.m,103,0">test_cir_image_reg at 103</a>
[motion_fwd, motion_bwd, ROI_t, ROI_s, evol_history] = cir_image_reg(img_template, img_source, params);

multi-resolution layer = 3
1-st round of optimization
# of iterations of Gauss-Seidel=4 out of max=5: cost too flat
2-st round of optimization
Saving minidump to file C:\DOCUME~1\fengwe1\LOCALS~1\Temp\matlab_crash_dump.3716.0.dmp

==================

Subject: Weird! MEX crash followed by "out of memory" after restarting matlab

From: wei feng

Date: 21 Feb, 2009 19:07:02

Message: 2 of 8

any suggestions?

Subject: Weird! MEX crash followed by "out of memory" after restarting matlab

From: James Tursa

Date: 21 Feb, 2009 20:07:02

Message: 3 of 8

"wei feng" <fengwe1@auburn.edu> wrote in message <gnpesr$gfh$1@fred.mathworks.com>...
> Hi all,
>
> I have a mex function which caused a crash ...

Posting a crash report doesn't help much. That simply means that your mex code is incorrect and is corrupting memory. You need to post the mex source code if we are to give you any help.

James Tursa

Subject: Weird! MEX crash followed by "out of memory" after restarting matlab

From: wei feng

Date: 21 Feb, 2009 21:14:01

Message: 4 of 8

Thanks for you time to reply.

I did not post my mex function because it was not clear to me which part of it was causing the problem and it is a complicated function (both in concept and length). I used two types of dynamic array allocation in my mex code. One is the mxCreate* function, which I used once as a local variable and I called mxDestroyArray after I finished using them.

The other type of dynamic array that I used was mxCalloc or mxMalloc. (I've been thinking about whether I should ask about this.) Basically I have a large data set that I need to go through repeatedly to find a proper subset to compute a value each time. For instance, you can imagine that I have a 1000x1000 array of data, and I need an uncertain # of entries (could be 10 or 10,000 depends on the condition) to compute a value each time. So I constructed a linked list of entries each time (using mxCalloc or mxAlloc) to record the used entries. I was using mxRealloc after the initial round to change the size of the dynamic array since the size of the entry list is changing. After I finished computing all the values, I called mxFree on the pointer to the dynamic arrays.

Woud you think the above senario caused the crash?

In fact, I omitted something in the above to make things easier to explain. In each iteration, I did not construct a simple linked list. I constructed a what you may call a blocked linked list. It has a kind of like 1.5-D structure. And by 1.5-D I mean the following. The list has a list of header elements (call it type1). Each header element contains a pointer to a linked list of type2 elements. Each type2 element contains a pointer that points to a block of dynamically allocated memory (by mxCalloc or mxMalloc) of limited size. So schematically the whole list looks like this:

H --> H --> H --> ... --> H
| | : |
v v : v
B B : B
| | : |
v v v
B B B
|
v
B

After each iteration, I have to construct this list again. So I call mxFree on this whole list in a nested fashion (starting from the first H, I traverse each B pointed by this H and free the block of memory pointed by B. Then I free the pointer to the B. Once all B's are freed, I free this H. Then I go to the next H and do the same thing. The code is copied below:
==============
void free_B_list(bBlock *p_bList)
{
bBlock *p_next=NULL;
while(p_bList){
p_next = p_bList->p_next;

if(p_bList->pg_block){
mxFree(p_bList->pg_block);
}
mxFree(p_bList);

p_bList = p_next;
}
return;
}

void free_H_list(hBlock *p_hList)
{
hBlock *p_next=NULL;
while(p_hList){
p_next = p_hList->p_next;

free_B_list(p_hList->p_bList);
mxFree(p_hList);

p_hList = p_next;
}
return;
}
=================

Do you see anything wrong here?

Thanks for the help.




"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gnpmt5$9oh$1@fred.mathworks.com>...
> "wei feng" <fengwe1@auburn.edu> wrote in message <gnpesr$gfh$1@fred.mathworks.com>...
> > Hi all,
> >
> > I have a mex function which caused a crash ...
>
> Posting a crash report doesn't help much. That simply means that your mex code is incorrect and is corrupting memory. You need to post the mex source code if we are to give you any help.
>
> James Tursa

Subject: Weird! MEX crash followed by "out of memory" after restarting matlab

From: James Tursa

Date: 22 Feb, 2009 06:05:02

Message: 5 of 8

"wei feng" <fengwe1@auburn.edu> wrote in message <gnpqqp$1bp$1@fred.mathworks.com>...
> Thanks for you time to reply.
>
> I did not post my mex function because it was not clear to me which part of it was causing the problem and it is a complicated function (both in concept and length). I used two types of dynamic array allocation in my mex code. One is the mxCreate* function, which I used once as a local variable and I called mxDestroyArray after I finished using them.
>
> The other type of dynamic array that I used was mxCalloc or mxMalloc. (I've been thinking about whether I should ask about this.) Basically I have a large data set that I need to go through repeatedly to find a proper subset to compute a value each time. For instance, you can imagine that I have a 1000x1000 array of data, and I need an uncertain # of entries (could be 10 or 10,000 depends on the condition) to compute a value each time. So I constructed a linked list of entries each time (using mxCalloc or mxAlloc) to record the used entries. I was using mxRealloc after the initial round to change the size of the dynamic array since the size of the entry list is changing. After I finished computing all the values, I called mxFree on the pointer to the dynamic arrays.
>
> Woud you think the above senario caused the crash?
>

Can't tell just from your description.

> ==============
> void free_B_list(bBlock *p_bList)
> {
> bBlock *p_next=NULL;
> while(p_bList){
> p_next = p_bList->p_next;
>
> if(p_bList->pg_block){
> mxFree(p_bList->pg_block);
> }
> mxFree(p_bList);
>
> p_bList = p_next;
> }
> return;
> }
>
> void free_H_list(hBlock *p_hList)
> {
> hBlock *p_next=NULL;
> while(p_hList){
> p_next = p_hList->p_next;
>
> free_B_list(p_hList->p_bList);
> mxFree(p_hList);
>
> p_hList = p_next;
> }
> return;
> }
> =================
>
> Do you see anything wrong here?
>
> Thanks for the help.
>

I don't see anything obviously wrong with your posted code, assuming everything was built properly. I suspect the problem is with the way you are allocating or using the allocated memory. It may be long, but can you post your other code, or a simplified version of it that reproduces the error?

James Tursa

Subject: Weird! MEX crash followed by "out of memory" after restarting matlab

From: Roland Neumann

Date: 23 Feb, 2009 13:09:02

Message: 6 of 8

As I learned from my (buggy) code, this is the error message pointing out a memory problem. I got it when writing return values of the mexfunction. Either you write different sized array to a plhs(x) pointer or you dind't free all used memory/accessed free'd memory. Just my guesses, you may post your return code.

Subject: Weird! MEX crash followed by "out of memory" after restarting matlab

From: wei feng

Date: 3 Mar, 2009 21:48:31

Message: 7 of 8

Thanks for all the reply. I used step by step execution and the "out of memory" complaint was gone. Although it still kept crashing, which was my fault because I made a typo for an indexing variable and it probably was pointing out of range. I corrected it and the code works with no problem now.

It still is a little weired to me as of the "Out of memory" phenomena. And I have no idea how that happened.



"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gnqpue$j22$1@fred.mathworks.com>...
>
> I don't see anything obviously wrong with your posted code, assuming everything was built properly. I suspect the problem is with the way you are allocating or using the allocated memory. It may be long, but can you post your other code, or a simplified version of it that reproduces the error?
>
> James Tursa

Subject: Weird! MEX crash followed by "out of memory" after restarting matlab

From: wei feng

Date: 3 Mar, 2009 21:48:31

Message: 8 of 8

Thanks for all the reply. I used step by step execution and the "out of memory" complaint was gone. Although it still kept crashing, which was my fault because I made a typo for an indexing variable and it probably was pointing out of range. I corrected it and the code works with no problem now.

It still is a little weired to me as of the "Out of memory" phenomena. And I have no idea how that happened.


"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gnqpue$j22$1@fred.mathworks.com>...
>
> I don't see anything obviously wrong with your posted code, assuming everything was built properly. I suspect the problem is with the way you are allocating or using the allocated memory. It may be long, but can you post your other code, or a simplified version of it that reproduces the error?
>
> James Tursa

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us