Solved

Programming Registry equals

Posted on 2013-05-18
13
452 Views
Last Modified: 2013-05-21
Hello;
How is Registry = { } used here, below.  In other words what is this statement doing in this function;
 function registerPerson(firstName, lastName)
  {
   var date = new Date(),
       counter = 0,
      registry = {},
       output;

Reference; http://milan.adamovsky.com/2012/02/javascript-memory-leaks-in-internet.html
If need to.
thanks
0
Comment
Question by:chima
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 39178471
0
 

Author Comment

by:chima
ID: 39178688
CEHJ, I read the info at the link you provided, and the answer is not there.  Did you understand my question?  I had googled it, and of course most of the findings were about the MS OS registry.
I do not understand what this statement is doing;    registry = {},
Obviously the registry variable is getting information from the registry, but what and why?
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 50 total points
ID: 39178702
Did you understand my question?
Well clearly you either didn't read or didn't understand the link i posted ;) Your question relates to JavaScript. This is the Java TA, not JavaScript
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:chima
ID: 39179737
CEHJ, what is TA?  You posted a question to my question?
0
 
LVL 49

Assisted Solution

by:PortletPaul
PortletPaul earned 150 total points
ID: 39179939
TA = topic area (an Experts Exchange abbreviation)

registry = {}

it is my belief that author of the article you reference used as an 'object literal'
An object literal is a list of zero or more pairs of property names and associated values of an object
https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Values,_variables,_and_literals#Object_literals

registry = {} sets it to null as there in nothing between those curly braces.
I think the idea of the article is to ensure variables get handled by the garbage collector, hence all the author is interested in is removing the memory reserved for "registry" - not what is contained in memory by "registry".
0
 
LVL 42

Accepted Solution

by:
David S. earned 300 total points
ID: 39179974
Yes, in JavaScript, "{}" is an object literal, when the curly braces are not being used to designate the beginning and end of the code block for a function, loop, or condition. Object and Array Literals are shorter ways of creating objects and arrays, respectively, than using the constructor functions for them:
var myArray = new Array();
var myObject = new Object();

Open in new window


registry = {} sets it to null as there in nothing between those curly braces.
An empty object is not the same as null. An empty object can have properties and methods added to it, whereas null would have to be redefined to an object before it could be given any properties.
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 39179988
I stand corrected - sorry. 'empty object' it is, my bad. In fact the original article reference does go on to explicitly set registry to null:

  // locals
   date =
   counter =
   registry = null;

   return output;

I hope the point is not lost though that there really is no great significance in registry = {} it is really just an example the author has used to reach a conclusion about garbage collection.
0
 

Author Comment

by:chima
ID: 39182297
PortletPaul and Kravimir, so the word registry could have been any variable name, the point here is that it created an "empty object."  This empty object by using {} has properties and methods that could cause memory leaks, hence setting it to null, ensuring that the garbage collection will grab it.
0
 
LVL 42

Expert Comment

by:David S.
ID: 39182322
Yes, that is my understanding as well.
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 39182973
the solution is to assist the garbage collector in JScript by marking the symbols with a null value that you want to be garbage collected.
I think so too. registry = {} could have been foobar = {}
0
 

Author Closing Comment

by:chima
ID: 39186157
Thanks
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question