How do I trace that memory error?

Marc jckj33 at gmail.com
Tue Feb 27 20:44:04 UTC 2018


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 at 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.


More information about the Digitalmars-d-learn mailing list