473,395 Members | 1,726 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,395 software developers and data experts.

reference and value

When I call sub in VB I can sent value of variable or reference to this
value. The question is. Suppose I have class
public class AA
....
end class
and declare object of this class
dim objAA as AA

Does objAA is value or it refers to memory where I keep appropriate value.
If objAA is value how I can declare it as reference?
Aug 6 '07 #1
4 1329
Aleks Kleyn wrote:
When I call sub in VB I can sent value of variable or reference to this
value.
I suppose that you mean the ByVal and ByRef keywords?

The ByRef keyword sends a variable _by_ reference. Don't confuse this
with sending _a_ reference, it's not the same thing at all.

When you send a variable by reference, the method can change the value
of that variable. When you send a variable by value, the method gets a
copy of the value, so that it can not change the variable itself.

The default for arguments is ByVal, and this is what you should normally
use. For a value type, sending by value means that a copy of the value
is sent to the method. For a reference type, it means that a copy of the
reference is sent to the method. The method can change the object that
the reference points to, but it can not change the reference variable
itself.
The question is. Suppose I have class
public class AA
...
end class
and declare object of this class
dim objAA as AA

Does objAA is value or it refers to memory where I keep appropriate value.
If objAA is value how I can declare it as reference?
A class is a reference type, so the variable objAA is a reference.

--
Göran Andersson
_____
http://www.guffa.com
Aug 7 '07 #2
Aleks Kleyn wrote:
So suppose I write code

class C1
...
end class
class C2
...
public objC1a as C1
...
end class
class myCode
dim objC1 as C1
dim objC2 as C2
public sub new
objC1=new C1
objC2=new C2
objC2.objC1a=objC1
end sub
end class

Then objC2.objC1a is just refference to objC1.
No, it's not a "refference", it's a reference. ;)
Then I have other qusetion. This means that objC2.objC1a has the same amount
of memory does not matter how much memory gets objC1.
Yes, a reference is always the same size.
Recently I posted
problem in thread asp 2.0 and memory leak. Eliyahu Goldin responded me on
8/1/07

Almost certainly the problem is in storing large amount of data in session
variables.

However this statement contradicts initial statement. And the question is:
where is the answer?
What's stored in the session variable is always a reference, so strictly
speaking what you store in a session variable is always the same size.

However, one does not usually speak that strictly about reference
variables. If you have a string variable, for example, you say that you
store a string in it, although what you actually do is store a reference
to a string in it.

When Eliyahu is talking about storing large objects in session
variables, he means putting references to large objects in session
variables. This is implied, as it obviously is impossible to store a
large object in a reference.

--
Göran Andersson
_____
http://www.guffa.com
Aug 8 '07 #3
I try to sumaris what I understand. If I store in session reference to large
object this object is allocated in address space of aspnet.exe. It does not
matter do I refer to this object from session collection, from application
collection or if I put this object in web service. Because size of this
object may vary in time it eventualy leads to memory leak when a lot of
people work with web site. So it better to make step back and simplify
design. It is good that I did this only on few pages.
Probably it would be better if separate process run for different session.
However it may be not proper solution. I am not sure if communication of web
site with desktop application can help to solve this problem.

Very close question. What will happens with LINQ. Should I expect there
similar problem?
"Göran Andersson" <gu***@guffa.comwrote in message
news:eR**************@TK2MSFTNGP03.phx.gbl...
Aleks Kleyn wrote:
>So suppose I write code

class C1
...
end class
class C2
...
public objC1a as C1
...
end class
class myCode
dim objC1 as C1
dim objC2 as C2
public sub new
objC1=new C1
objC2=new C2
objC2.objC1a=objC1
end sub
end class

Then objC2.objC1a is just refference to objC1.

No, it's not a "refference", it's a reference. ;)
>Then I have other qusetion. This means that objC2.objC1a has the same
amount of memory does not matter how much memory gets objC1.

Yes, a reference is always the same size.
>Recently I posted problem in thread asp 2.0 and memory leak. Eliyahu
Goldin responded me on 8/1/07

Almost certainly the problem is in storing large amount of data in
session variables. However this statement contradicts initial statement.
And the question is: where is the answer?

What's stored in the session variable is always a reference, so strictly
speaking what you store in a session variable is always the same size.

However, one does not usually speak that strictly about reference
variables. If you have a string variable, for example, you say that you
store a string in it, although what you actually do is store a reference
to a string in it.

When Eliyahu is talking about storing large objects in session variables,
he means putting references to large objects in session variables. This is
implied, as it obviously is impossible to store a large object in a
reference.

--
Göran Andersson
_____
http://www.guffa.com
Aug 8 '07 #4
Aleks Kleyn wrote:
I try to sumaris what I understand. If I store in session reference to
large object this object is allocated in address space of aspnet.exe.
Well, nothing is allocated when you store the reference in the session
variable. The memory was allocated when you created the object.
It
does not matter do I refer to this object from session collection, from
application collection or if I put this object in web service. Because
size of this object may vary in time it eventualy leads to memory leak
when a lot of people work with web site.
The size of a specific object doesn't vary, it's always the same.

It's not a memory leak, it's memory that you lost control over. You
leave it in the hands of session objects that aren't used any more. The
memory will be collected when the sessions ends, but you have no control
over when that happens.
So it better to make step back
and simplify design.
Correct.
It is good that I did this only on few pages.
Probably it would be better if separate process run for different
session. However it may be not proper solution. I am not sure if
communication of web site with desktop application can help to solve
this problem.
You just have to take control over the objects that you handle. If you
really need to keep that much information available, you should not
store all of it in memory.
Very close question. What will happens with LINQ. Should I expect there
similar problem?
That's not close at all. LINQ is just a new way of writing things that
already exist. It will not change the fact that you have to keep track
of your objects.

--
Göran Andersson
_____
http://www.guffa.com
Aug 8 '07 #5

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

Similar topics

26
by: Dave Hammond | last post by:
In document "A.html" I have defined a function and within the document body have included an IFRAME element who's source is document "B.html". In document "B.html" I am trying to call the function...
4
by: z_learning_tester | last post by:
I'm reading the MS press C# book and there seems to be a contradiction. Please tell me which one is correct, 1 or 2. Thanks! Jeff 1. First it gives the code below saying that it prints 0 then...
19
by: daniel | last post by:
This is a pretty basic-level question, but I'd really like to know, so thanks for any help or pointers you can provide (like what I would google for ;o) Suppose: <code> myFunc() {
6
by: Chris Simmons | last post by:
I know that a String is immutable, but I don't understand why this piece of code fails in nUnit: // BEGIN CODE using System; class Test { public static void Main( String args )
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
51
by: Kuku | last post by:
What is the difference between a reference and a pointer?
9
by: Edward Diener | last post by:
Can one use 'ref' ( or 'out' ) on a reference type to create a reference to a reference in C#. I know one can use it on a value type to create a reference to that value.
10
by: Robert Dailey | last post by:
Hi, I noticed in Python all function parameters seem to be passed by reference. This means that when I modify the value of a variable of a function, the value of the variable externally from the...
68
by: Jim Langston | last post by:
I remember there was a thread a while back that was talking about using the return value of a function as a reference where I had thought the reference would become invalidated because it was a...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.