Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ngMessages memory leak with unmatchedMessages.push(messageCtrl); #14067

Closed
@marcdexet

Description

@marcdexet

Hi

Description

We migrated from ngMessages 1.3 to 1.4 and we have a memory leak we do not understand, in the render function, there's an infinite loop that pushes more than 100000 element in unmatchedMessages via

 unmatchedMessages.push(messageCtrl);

We don't understand why this loop nerver end

EDIT
It should be a problem in messageItem construction becauseof we have this test ever true:

  messageItem === messageItem.next;

How could this be possible ?

To my humble opinion this no a normal behavior, even if we miss something

Context

Overview of the Issue - No stack
Motivation for or Use Case - silent memory leak
Angular Version(s): 1.4.8
Browsers and Operating System - Chrome Version 46.0.2490.71 m (64-bit) / Firefox 43.0.4 / Windows 7

Involved piece of code

return {
       require: 'ngMessages',
       restrict: 'AE',
       controller: ['$element', '$scope', '$attrs', function($element, $scope, $attrs) {
 ...

         this.render = function(collection) {
           collection = collection || {};
           while (messageItem != null) {
             totalMessages++;
             var messageCtrl = messageItem.message;

             var messageUsed = false;
             if (!messageFound) {
               forEach(collection, function(value, key) {
                 if (!messageUsed && truthy(value) && messageCtrl.test(key)) {
                   // this is to prevent the same error name from showing up twice
                   if (matchedKeys[key]) return;
                   matchedKeys[key] = true;

                   messageUsed = true;
                   messageCtrl.attach();
                 }
               });
             }

             if (messageUsed) {
               // unless we want to display multiple messages then we should
               // set a flag here to avoid displaying the next message in the list
               messageFound = !multiple;
             } else {
/*>>>>>>>>>>>>>>>>>> HERE <<<<<<<<<<<<<<<<<<<<<<<*/
               unmatchedMessages.push(messageCtrl);
/*>>>>>>>>>>>>>>>>>> HERE <<<<<<<<<<<<<<<<<<<<<<<*/
             }

/*>>>> ( messageItem === messageItem.next) is ever true<<<<<<<<*/
             messageItem = messageItem.next;
/*>>>>>>>>>>>>>>>>>> HERE <<<<<<<<<<<<<<<<<<<<<<<*/
           }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions