Programming Registry equals

Posted on 2013-05-18
Last Modified: 2013-05-21
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 = {},

If need to.
Question by:chima
  • 4
  • 3
  • 2
  • +1
LVL 86

Expert Comment

ID: 39178471

Author Comment

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?
LVL 86

Assisted Solution

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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.


Author Comment

ID: 39179737
CEHJ, what is TA?  You posted a question to my question?
LVL 48

Assisted Solution

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,_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".
LVL 42

Accepted Solution

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.
LVL 48

Expert Comment

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.

Author Comment

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.
LVL 42

Expert Comment

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

Expert Comment

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 = {}

Author Closing Comment

ID: 39186157

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javascript Case Expression 7 29
Desingning Refactoring existing code 2 24
how can i apply an assert arrayEqual function ? 2 24
mysql jsp example issue 32 32
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

816 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now