Solved

Programming Registry equals

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

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

762 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

18 Experts available now in Live!

Get 1:1 Help Now