www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How do I trace that memory error?

reply Marc <jckj33 gmail.com> writes:
I've tried both gdb and windbg debugger both it either get a 
"received signal ?" from gdb or crash the GUI application 
(windbg).
The error is:

 core.exception.OutOfMemoryError src\core\exception.d(696): 
 Memory allocation failed
How do I find out the source of the error?
Feb 26 2018
next sibling parent Marc <jckj33 gmail.com> writes:
On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote:
 I've tried both gdb and windbg debugger both it either get a 
 "received signal ?" from gdb or crash the GUI application 
 (windbg).
 The error is:

 core.exception.OutOfMemoryError src\core\exception.d(696): 
 Memory allocation failed
How do I find out the source of the error?
I'm allocation a class and returning it in a yield. Can it be related? Something like this:
 Generator!Field fromCSVFile(in string csvFilename) {
	return new Generator!Field({
		string line;
		while((line = csvFile.readln()) !is null) {
			Field field = deserializeLine(line);
			yield(field);
			writeln("----------------------------------------");
		}
	});
 }
Feb 26 2018
prev sibling next sibling parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote:
 I've tried both gdb and windbg debugger both it either get a 
 "received signal ?" from gdb or crash the GUI application 
 (windbg).
 The error is:

 core.exception.OutOfMemoryError src\core\exception.d(696): 
 Memory allocation failed
How do I find out the source of the error?
"received signal ?" seems like the one of the GC signals used for stopping threads. just get gdb to ignore those.
Feb 27 2018
parent Marc <jckj33 gmail.com> writes:
On Tuesday, 27 February 2018 at 14:06:19 UTC, Nicholas Wilson 
wrote:
 On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote:
 I've tried both gdb and windbg debugger both it either get a 
 "received signal ?" from gdb or crash the GUI application 
 (windbg).
 The error is:

 core.exception.OutOfMemoryError src\core\exception.d(696): 
 Memory allocation failed
How do I find out the source of the error?
"received signal ?" seems like the one of the GC signals used for stopping threads. just get gdb to ignore those.
An attempt to continue results in crash. I also added in my foreach's body:
		scope(exit) {
			import core.memory : GC;
			GC.collect();
                }
But also doesn't solve the issue.
Feb 27 2018
prev sibling parent reply Stefan Koch <uplink.coder googlemail.com> writes:
On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote:
 I've tried both gdb and windbg debugger both it either get a 
 "received signal ?" from gdb or crash the GUI application 
 (windbg).
 The error is:

 core.exception.OutOfMemoryError src\core\exception.d(696): 
 Memory allocation failed
How do I find out the source of the error?
I'd say allocating in a loop is a bad idea :) perhaps you should start with posting the code that leads to this.
Feb 27 2018
next sibling parent Marc <jckj33 gmail.com> writes:
On Tuesday, 27 February 2018 at 15:08:23 UTC, Stefan Koch wrote:
 On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote:
 I've tried both gdb and windbg debugger both it either get a 
 "received signal ?" from gdb or crash the GUI application 
 (windbg).
 The error is:

 core.exception.OutOfMemoryError src\core\exception.d(696): 
 Memory allocation failed
How do I find out the source of the error?
I'd say allocating in a loop is a bad idea :) perhaps you should start with posting the code that leads to this.
The code is that one on my second post. The deserializeLine() create allocate instance of Field then return. So yeah, I'm allocating on loop but I don't doing too much. I was watching the memory usage of the application (with win10 taskbar memory usage feature) and I saw it uses only about 4mb on 8gb machine. I've tried build a 64bit executable but I got same error.
Feb 27 2018
prev sibling parent reply Marc <jckj33 gmail.com> writes:
On Tuesday, 27 February 2018 at 15:08:23 UTC, Stefan Koch wrote:
 On Monday, 26 February 2018 at 18:01:07 UTC, Marc wrote:
 I've tried both gdb and windbg debugger both it either get a 
 "received signal ?" from gdb or crash the GUI application 
 (windbg).
 The error is:

 core.exception.OutOfMemoryError src\core\exception.d(696): 
 Memory allocation failed
How do I find out the source of the error?
I'd say allocating in a loop is a bad idea :) perhaps you should start with posting the code that leads to this.
I've also tried to create only one instance: create a local variable inside the method then reuse it. I get same error. No debugg tool has helped so far.
Feb 27 2018
parent Marc <jckj33 gmail.com> writes:
On Tuesday, 27 February 2018 at 16:55:27 UTC, Marc wrote:
 [...]
So deep down the error is in that method which I call from deserializeLine() function:
		void setValue(T, V)(auto ref T aggregate, string field, V 
value) {
			writeln("setting {", field, "} to {", value, "}");
		    import std.traits : FieldNameTuple;
		    import std.meta : Alias;
		    switch (field) {
		        foreach (fieldName; FieldNameTuple!T) {
		            case fieldName:
		                static if (is(typeof(__traits(getMember, 
aggregate, fieldName) = value))) {
		                    __traits(getMember, aggregate, fieldName) 
= value;
		                    return;
		                } else {
		                	assert(false, T.stringof ~ "."~field~" cannot 
be assigned from a "~V.stringof~".");
		                }
		        }
		        default:
		            assert(false, T.stringof ~ " has no field named 
"~field~".");
		    }
		}
the function is used like this:
			Field field = new Field();
			foreach(CSVLinkedIndex linkedIndex; linkedIndexes) {
				string value = values[linkedIndex.csv_column_index];
				setValue(field, linkedIndex.field_member, value);
			}
which eventually (in about 8 calls) return the error:
core.exception.OutOfMemoryError src\core\exception.d(702): 
Memory allocation failed
it uses about 4MB in a 8GB machine then crashs. It's return by the top function using yield:
yield(field);
But I can't find out why gc fails to allocate at some point. In fact, I've forced the gc to do so in my top loop:
foreach(Field field; deserializeFile()) {
scope(exit) {
	import core.memory : GC;		
        GC.collect();
}
}
Which didn't solve the issue.
Feb 27 2018