Solved

Programming Registry equals

Posted on 2013-05-18
13
443 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
  • 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
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

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

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 48

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 48

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

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