Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Programming Registry equals

Posted on 2013-05-18
13
Medium Priority
?
470 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 200 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 600 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 43

Accepted Solution

by:
David S. earned 1200 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 43

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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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…

688 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