473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

object references stored in array gives me what?

I'm nervous this method is not doing what I assumed it was doing. Does
it not create objects, store them in an array, and check that array to
see if a requested class has already been instantiated, in which case
it gets a reference out of the array and returns that, again by
reference?

I'm getting out of memory error, meaning my scrip is using the 8 megs
that PHP scripts are, by default, allowed. So I'm left to think I've
done something wrong with the references.

function & getObject($nameOfClassToBeUsed) {
if (!$nameOfClassToBeUsed) {
print "Sorry, but the code wants to create a software object, but
in the method called 'getObject' and in the class called
McControllerForAll, it's just being handed an empty string instead of
the correct name for whatever software object it is supposed to
create. The most common reason for this to happen is if something is
set wrong in the config file, especially if 'defaultQueryObject' is
set incorrectly.";
return false;
}
if (array_key_exists($nameOfClassToBeUsed,
$this->arrayOfAllTheObjectsSoFarLoaded)) {
$object = & $this->arrayOfAllTheObjectsSoFarLoaded[$nameOfClassToBeUsed];
return $object;
} elseif (class_exists($nameOfClassToBeUsed)) {
// 10-13-03 - in the 2 lines above we look to see if an instance of
this class already exists in
// $this->arrayOfAllTheObjectsSoFarLoaded. If so, we want to return
it. But if not, then we want to see
// whether such a class is known of. If yes, then we create an
instance of it. If not, then we will skip down
// below and run import() in the hopes of finding it.
$object = new $nameOfClassToBeUsed();
$this->arrayOfAllTheObjectsSoFarLoaded[$nameOfClassToBeUsed] =
$object;
return $object;
} else {
// 10-10-03 - hopefully this method doesn't get this far because
the needed object has already been found
// and the "return" keyword has stopped execution of the method.
But if we get this far, then we run import
// because we've got to find this object
$this->import($nameOfClassToBeUsed);
// 10-13-03 - now that we've run import() we try again to see if
this class exists
if (class_exists($nameOfClassToBeUsed)) {
$object = new $nameOfClassToBeUsed();
$this->arrayOfAllTheObjectsSoFarLoaded[$nameOfClassToBeUsed] =
$object;
return $object;
} else {
print "<hr>Error: Awful sorry, but after poking about a bit the
software still can't quite to seem to find a file, object, or class
called $nameOfClassToBeUsed and the object known as controllerForAll
really needs it. It feels badly about this, of course, and worries
this will have a negative effect on your day. However, the real shod
in this case is probably not the software itself, but some programmer,
who was probably quite gone when they wrote whatever lines of code
necessitated the software printing this error. However, in fairness,
we must ask if you haven't moved any files lately, or played wreck
with your installation, or poked about where you shouldn't have, and
if yes, could you please put everything back the way it was? Please
note, if you're a programmer, and you're debugging, and the software
can't find a PHP file which you know is there, that means there is a
parse error in that file.<hr>";
}
}
}
Jul 17 '05 #1
4 2105
Hi lawrence,

I don't think that this causes your problem, but there is
a reference-operator missing (two times), if you do not
want to clone the objects:
$this->arrayOfAllTheObjectsSoFarLoaded[
$nameOfClassToBeUsed] = $object;


You should use =& instead of =. And are you assigning the
result of getObject() via &= ?

I can't see what should eat up the 8 megabyte of memory.
May be the import-function causes this problem? Or may be
there is a huge object being created?

Greetings from Frankfurt / Germany,

Fabian Wleklinski
Jul 17 '05 #2
"Fabian Wleklinski" <Wl*************@eWorks.de> wrote in message news:<bm********@library1.airnews.net>...
Hi lawrence,

I don't think that this causes your problem, but there is
a reference-operator missing (two times), if you do not
want to clone the objects:
$this->arrayOfAllTheObjectsSoFarLoaded[
$nameOfClassToBeUsed] = $object;
You should use =& instead of =. And are you assigning the
result of getObject() via &= ?


You are right, I have made that change.


I can't see what should eat up the 8 megabyte of memory.
May be the import-function causes this problem? Or may be
there is a huge object being created?


It fails when it has to get out all the weblog entries for the page. I
think my front page posts 50 entries. On the advice of Phillip
Greenspun and Edward Tufte I allow my front page to be heavy with text
(I've been debugging on my personal site). But even then, it is only
about 200k, or 250k at most. I realize there are extraneous elements
that don't get printed. But even if they doubled the size, that would
only be 500k. Now some operations involve making a copy of this
array, like when I strip slashes from the array while copying it to a
new one. But even then, the size of the 2 arrays should only be a meg,
plus some overhead. It is hard for me to imagine where the extra 7
megs come from. I wish there was a way to take a snap shot of the
state of script at any given time.
Jul 17 '05 #3
Hi Lawrence,

if you handle large objects (> 250K) it would make sense to free
some memory explicitely.

Example given, after an operation like $text=addslashes($oldtext)
you could free $oldtext using unset( $oldtext ), or alternatively
using the same variable:

$text = addslashes($text); // this works as well

Search for all assignments concerning the "large variables", and
check if referencing or copying is used.

Greetings from Frankfurt,

Fabian
Jul 17 '05 #4
"Fabian Wleklinski" <Wl*************@eWorks.de> wrote in message news:<bm********@library1.airnews.net>...
Hi Lawrence,

if you handle large objects (> 250K) it would make sense to free
some memory explicitely.

Example given, after an operation like $text=addslashes($oldtext)
you could free $oldtext using unset( $oldtext ), or alternatively
using the same variable:

$text = addslashes($text); // this works as well

Search for all assignments concerning the "large variables", and
check if referencing or copying is used.

Greetings from Frankfurt,

Thank you, that is good advice. I will begin to use unset() to
explicitly recoup the memory allocated to no longer needed variables
and objects.
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
by: VK | last post by:
Hello, In my object I have getDirectory() method which returns 2-dimentional array (or an imitation of 2-dimentional array using two JavaScript objects with auto-handled length property - please...
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
4
by: IanONet | last post by:
I had a need for a two dimentional array. Looking for this solution, I ran accross a statement than all Javascipt arrays were arrays of objects. So I created a function prototype, at least thats...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.