Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9192629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:58:18+00:00 2026-06-17T20:58:18+00:00

var GlobalObject = (function(){ var arr1 = []; var arr2 = []; var arr3

  • 0
var GlobalObject = (function(){

    var arr1 = [];
    var arr2 = [];
    var arr3 = [];
    var arr4 = []; 

        return {

         }

})();
  1. Now how would i call GlobalObject.arr1 across the application?
  2. Will it maintain its reference and value, when i do a push and pop.
  3. Will this cause any memory leak
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:58:19+00:00Added an answer on June 17, 2026 at 8:58 pm

    arr1 is defined only within the scope of the GlobalObject function. If you want to access it globally, you need to have the GlobalObject function return a reference to it. Read up on functional scope in javascript for a better understanding of this. Currently your function returns an empty object. You want to do something like this:

    ...
    return {
       "array1": arr1,
       "array2": arr2,
       "array3": arr3,
       "array4": arr4
    };
    

    (though you can maintain the privacy of those arrays by not returning them)

    The GlobalObject will maintain arr1‘s reference and value until you manually de-reference it (setting it to null). Javascript’s garbage collector only deletes objects that aren’t needed anymore.

    Your current code shows no memory leaks. Watch out for circular references and closures.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var ref1 = new Firebase(http://gamma.firebase.com/myuser/123,456); ref1.set(123,456); var on1 = ref1.on(value, function(snapshot) { console.log(snapshot.val()); });
var Foo = Foo || {}; Foo.Controller = (function ($) { var $page =
var JavascriptHelper = Backbone.Model.extend(JavascriptHelper, {}, // never initialized as an instance { myFn: function()
var search= document.getElementById('appMenu').value document.location.href= '${createLink(controller: 'application' , action:'ajaxAppSearch', params: ['query': search])}' The element appMenu
var messageSpan; function createFlashMessage = function(message, type, time) { messageSpan || (messageSpan = $(<span>).hide().appendTo(body));
Please help with my problem described below: var Land = function(){ this.cities = [];
Let's say I have a class: var asdf = new Class({ myFunction: function ()
Observe the following: function array_map(array, callback) { for (var i = 0; i <
I'm playing around with different ways to call a function that is an attribute
It's common to see CommonJS modules defined using the following idiom: (function() { var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.