Memory leak issue

46 views
Skip to first unread message

Marpoeh

unread,
Apr 24, 2012, 6:19:02 AM4/24/12
to JavaScript Templates Engine PURE
Hi,

i have a problem with pure and IE. We create dynamically page and load
load of cards. The cards are templates.

function FillCardInColumn(goal, container) {

var template = goal.Template;
eval("var jsonDirectives = " + goal.TemplateDirective + ";");
var jqueryTemplate = $(template);

$(container).append(jqueryTemplate);

jqueryTemplate.render(goal, jsonDirectives);
}

Now every time when i use F5 in IE, the memory amount grows per 5 MB.
If i disable the
jqueryTemplate.render(..
it´s all fine. This only happens in IE. Firefox and Chrome is ok. Only
tested it with IE 9 on several pcs and it´s reprocuable.
We use current version auf pure and jquery.

Any suggestions or help? Thanks a lot.
Martin

Mic (BeeBole)

unread,
Apr 25, 2012, 3:41:14 AM4/25/12
to JavaScript Templates Engine PURE
It is strange, the internal replaceWith function is designed precisely
to avoid memory leaks in IE.
Can you make a full example that leaks? (JSON data, the directive, and
the HTML, like this: https://gist.github.com/2323464 )

rgud...@googlemail.com

unread,
May 4, 2012, 6:27:11 AM5/4/12
to JavaScript Templates Engine PURE
Hi there,

I'm with Martin, and was able to narrow the issue down a bit.
Our directive look somewhat like this:

{
"a":"SystemId",
"a@href":"WebAccessUrl",
"div.AssignedTo":"SystemAssignedTo",

"div.ActivationTime": function(args){
var posSpace =
args.context.MicrosoftVSTSCommonActivatedDate.indexOf(" ");
if(posSpace > 0){
return
args.context.MicrosoftVSTSCommonActivatedDate.substr(0,posSpace);
}

return args.context.MicrosoftVSTSCommonActivatedDate;
},

"div.DurationTime": function(args){
var posSpace = args.context.MicrosoftVSTSCommonActivatedDate.length;
if(posSpace == 19){
[heavy use of string and date operations here]
return " " + numberofDays + "d";
}

return "";
}
}

The template is just a table with some div's, and the json data is
just a bunch of string properties. Nothing fancy here.
The memory is leaked because of the two functions defined in the
directive. It seems like the use of string operations could be a
problem here, as other functions that don't use string operations,
don't cause leaks (or at least, no noticable leak)
I'm not much into JavaScript, but I could not find any issues
about .substring() itself causing memory leaks, thus we think there
might be an issue in the way pure handles these functions.

Hope this helps.
René

Mic (BeeBole)

unread,
May 5, 2012, 3:50:25 AM5/5/12
to JavaScript Templates Engine PURE
It is hard to guess not knowing what goal is. A working example would
help.

Serialize goal with JSON.stringify(goal, null, 2), place it to an HTML
page with just the heavy string function.
Make it work standalone, insure it leaks and paste it to http://gist.github.com

Did you try to change the function call?
something like:

function FillCardInColumn(goal, container) {
$( container ).append(
$( goal.template ).render(
goal,
JSON.parse( goal.TemplateDirective )
)
);
}

The goal object, contains the template, the directive and the data,
and you pass it full to the render.
That's a lot of useless data/memory to deal with.
Reply all
Reply to author
Forward
0 new messages