473,796 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($name OfClassToBeUsed ) {
if (!$nameOfClassT oBeUsed) {
print "Sorry, but the code wants to create a software object, but
in the method called 'getObject' and in the class called
McControllerFor All, 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 'defaultQueryOb ject' is
set incorrectly.";
return false;
}
if (array_key_exis ts($nameOfClass ToBeUsed,
$this->arrayOfAllTheO bjectsSoFarLoad ed)) {
$object = & $this->arrayOfAllTheO bjectsSoFarLoad ed[$nameOfClassToB eUsed];
return $object;
} elseif (class_exists($ nameOfClassToBe Used)) {
// 10-13-03 - in the 2 lines above we look to see if an instance of
this class already exists in
// $this->arrayOfAllTheO bjectsSoFarLoad ed. 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 $nameOfClassToB eUsed();
$this->arrayOfAllTheO bjectsSoFarLoad ed[$nameOfClassToB eUsed] =
$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($nameOf ClassToBeUsed);
// 10-13-03 - now that we've run import() we try again to see if
this class exists
if (class_exists($ nameOfClassToBe Used)) {
$object = new $nameOfClassToB eUsed();
$this->arrayOfAllTheO bjectsSoFarLoad ed[$nameOfClassToB eUsed] =
$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 $nameOfClassToB eUsed and the object known as controllerForAl l
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 2123
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->arrayOfAllTheO bjectsSoFarLoad ed[
$nameOfClassToB eUsed] = $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.airn ews.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->arrayOfAllTheO bjectsSoFarLoad ed[
$nameOfClassToB eUsed] = $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=addslashe s($oldtext)
you could free $oldtext using unset( $oldtext ), or alternatively
using the same variable:

$text = addslashes($tex t); // 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.airn ews.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=addslashe s($oldtext)
you could free $oldtext using unset( $oldtext ), or alternatively
using the same variable:

$text = addslashes($tex t); // 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
5238
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 let's us do not go into an "each dot over i" clarification discussion now - however you want to call - you call it ;-) array contains records of all files in the current dir. array contains records of all subs in the current dir
5
2521
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: System.Runtime.InteropServices.Marshal.ReleaseComObject(Obj);
4
1441
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 what I was calling it: function objRow(vartype, varaddr1, varaddr2) { this.type = vartype; this.addr1 =varaddr1; this.addr2 =varaddr2;
275
12415
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
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10455
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10228
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10173
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10006
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.