Hi,
I've started using Java recently so the question may seem trivial.
Is it possible to get rid of an object by simply creating a method (let's
call it "die") in which one simply includes the instruction: "this = null;"
? Would that work if the object has been previously placed in a list of
similar objects? Do I need to go and delete it from the list or simply that
list would now reference a "null" object? If so what would the size() of
that list return in such case? Probably the same size I would guess. I would
also guess things would work as long as one can live with "null" objects in
the list.
Thx,
Alex 7 5286
In article
<4D************ *********@news0 1.bloor.is.net. cable.rogers.co m>, al************* @hotmail.com says... Hi, I've started using Java recently so the question may seem trivial. Is it possible to get rid of an object by simply creating a method (let's call it "die") in which one simply includes the instruction: "this = null;"
To me, it sounds like a very efficient way to add bugs to your code at an
amazing rate.
You can do all this stuff, but it's exactly what the developers of the
language had hoped to relieve developers from the burden of handling. If
you really need to make an object inaccessible, I think it would be
preferrable to have a boolean instance variable called, for instance,
'active' which must have a value of true before any methods are allowed
to execute. Let the JVM worry about garbage-collection.
--
"It is impossible to be unjust or unfair to the rich and powerful"
-- Harry Britt
"Joe" <sf***@spamcop. net> wrote in message
news:MP******** *************** *@sfo.news.spea keasy.net... In article <4D************ *********@news0 1.bloor.is.net. cable.rogers.co m>, al************* @hotmail.com says... Hi, I've started using Java recently so the question may seem trivial. Is it possible to get rid of an object by simply creating a method
(let's call it "die") in which one simply includes the instruction: "this =
null;"
To me, it sounds like a very efficient way to add bugs to your code at an amazing rate. You can do all this stuff, but it's exactly what the developers of the language had hoped to relieve developers from the burden of handling. If you really need to make an object inaccessible, I think it would be preferrable to have a boolean instance variable called, for instance, 'active' which must have a value of true before any methods are allowed to execute. Let the JVM worry about garbage-collection.
But that's exactly want I want to do. How can the garbage-collection worry
about it if there are still references to the object. GC would remove it if
there are no more references and this can be achieved by setting the pointer
to the object to NULL...
The flag solution is not very good in my case because I'm creating and
removing thousands (maybe hundred of thousands) of these things.
Alex
"Alexander Tulai" <al************ *@hotmail.com> wrote in message news:<4D******* **************@ news01.bloor.is .net.cable.roge rs.com>... Hi, I've started using Java recently so the question may seem trivial. Is it possible to get rid of an object by simply creating a method (let's call it "die") in which one simply includes the instruction: "this = null;" ? Would that work if the object has been previously placed in a list of similar objects? Do I need to go and delete it from the list or simply that list would now reference a "null" object? If so what would the size() of that list return in such case? Probably the same size I would guess. I would also guess things would work as long as one can live with "null" objects in the list. Thx, Alex
No. You can't do that. "this" is a final variable, and you cannot
programmaticall y change it in an object.
Regards. da*****@terraco x.syzygy-tech.com (Dai Ichi) wrote in
news:e5******** *************** ***@posting.goo gle.com: No. You can't do that. "this" is a final variable, and you cannot programmaticall y change it in an object.
In addition to that, even it this were non-final, it still is just another
reference to your object, so by setting this to null, you would break just
that one reference (and possibly invalidate most of the code of your object
in the mean time, including code required to clean it up), but your queue
would still contain a reference to the object.
In article
<Tj************ *********@news0 1.bloor.is.net. cable.rogers.co m>, al************* @hotmail.com says... But that's exactly want I want to do. How can the garbage-collection worry about it if there are still references to the object. GC would remove it if there are no more references and this can be achieved by setting the pointer to the object to NULL...
Then, what you want to do is to be able to programmaticall y remove all
the references to your objects?
The flag solution is not very good in my case because I'm creating and removing thousands (maybe hundred of thousands) of these things.
Alex
So? The number of objects is irrelevant.
You are correct.
But wouldn't that (the idea , not necessarily the means proposed) be a
great idea of getting rid of objects without having to go around and clean
any structures referencing it?
Object Ox --->Ptr to Object Ox --> Ptr to Ptr. to Objexct Ox
The reference structure should use Ptr to Ptr. to Object Ox
If one wants to kill the object just makes Ptr to Object Ox = null.
Now, because there is no more references to Object Ox , the Garbage
Collector will take care of it.
Meantime, the rest of the structures using Ptr to Ptr. to Objexct Ox should
be smart enough to detect when Ptr to Object Ox == null and clean themself
up ....!
Thanks all for your feedback.
Alex
"Dai Ichi" <da*****@terrac ox.syzygy-tech.com> wrote in message
news:e5******** *************** ***@posting.goo gle.com... "Alexander Tulai" <al************ *@hotmail.com> wrote in message
news:<4D******* **************@ news01.bloor.is .net.cable.roge rs.com>... Hi, I've started using Java recently so the question may seem trivial. Is it possible to get rid of an object by simply creating a method
(let's call it "die") in which one simply includes the instruction: "this =
null;" ? Would that work if the object has been previously placed in a list of similar objects? Do I need to go and delete it from the list or simply
that list would now reference a "null" object? If so what would the size() of that list return in such case? Probably the same size I would guess. I
would also guess things would work as long as one can live with "null" objects
in the list. Thx, Alex
No. You can't do that. "this" is a final variable, and you cannot programmaticall y change it in an object.
Regards.
Hi,
Dai Ichi wrote: ...
No. You can't do that. "this" is a final variable, and you cannot programmaticall y change it in an object.
The "this" variable is not a field, it is a local variable implicitly
defined in all non-static methods and, of course, always refers to
the instance upon which the method was invoked. Even if it could be
zeroed out, it would not affect garbage collection. It would merely
sever the connection between the method invocation and the instance on
which it was operating.
Randall Schulz This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Timo J |
last post by:
Hi - Im sitting and trying to understand this OOP - and need to create a
class wich can do the following..
ShowBlocks() - Displays the data wich is inside it - If empty creates a form
wich sends the info back to the Object, wich show the stuff..
AddBlock( $type ) - Creates an empty blok - wich is addet to a blocks area
object...( Or somethin like it )
Store() - safes the info into a file, and updates mySQL...
I have figured out most...
|
by: Eyal |
last post by:
Hey,
I would appriciate if anyone can help on this one:
I have a java object/inteface having a method with a boolean
parameter. As I'm trying to call this method from a javascript it
fails on a type mismatch.
It is positively because of the boolean(java primitive)parameter. It
goes fine if I change this parameter to int or String.
This inteface has a lot more methods which works fine, it is just the
|
by: Joe Schmoe |
last post by:
All I want to to be able to take a two-column DataReader (One column with
the Item ID number, the other with Item Description text) and load it into a
Windows Forms ComboBox (Set to DropDownList mode) so that I the dropdown
shows the Item Descriptions, but returns the Item ID number when selected.
Completely easy in ASP.NET, but I cannot figure out how to do the same in a
Windows Forms app. Obviously the Windows Forms ComboBox is a lot more...
|
by: paul |
last post by:
HI! I keep on getting this error and I have tried different things but I am
not sure how to send the expiring date.
The error that I am getting in Firefox 1.5 is
"Error: expires.toGMTString is not a function"
----------------------------------------------------
I have this in a .js file and in the head section.
|
by: Grant Schenck |
last post by:
Hello,
I have a Windows Service developed in C# .NET. I'm making it a remote
server and I can, via an IPC Channel, expose methods and call them from a
client. However, I now want my remoted object to be able to invoke a method
on my server object and given that the object is built in a C# Class DLL
shared between the client and server I'm not sure how to get access to the
server object from the remoted object.
So, what techniques...
| |
by: ronchese |
last post by:
I'm noticing this since I started developing a website project: my session variables are getting empty!
I did a real easy test, and I checked my session variable is getting empty!! What is happening?
For example (VS2005, IE6/7, running in filesystem):
- In the Page_load of page1.aspx:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Throw New Exception("Error is thrown")
End Sub
|
by: rocketfire97 |
last post by:
I'm trying to call a COM object using C# but having no luck getting
values back for passed in ref objects.
I've tried the same call using VB.NET and can get data back. How would
I implement the following in C#
This is the method I am calling, which populates ref paramters with
results.
Sub Check_Customer(ByVal Customer As String, Optional ByRef oParam1 As
|
by: ced69 |
last post by:
having trouble getting marquee to work get object required errors
tring t <title>This Month at the Chamberlain Civic Center</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<script src="Dunbarlab9.js" type="text/javascript"></script>
<script type="text/javascript">
|
by: sony.m.2007 |
last post by:
Hi,
When i try to set a value for a session variable I'm getting a object
refence not set error
I tried two methods as below
HttpContext.Current.Session.Add("AppStartTime", DateTime.Now);
HttpContext.Current.Session = DateTime.Now;
For the above two methods I'm getting error as
"Object reference not set to an instance of an object."
|
by: =?Utf-8?B?RmFicml6aW8gQ2lwcmlhbmk=?= |
last post by:
I need to access classic ASP intrinsic objects and their properties from a
..net assembly wrapped to COM. The COM .net assembly is then instanciated from
a classic ASP page with Server.CreateObject().
I'm trying to use the Microsoft Transaction Server this way:
Type typeMtx = Type.GetTypeFromProgID("MTxAS.AppServer.1");
object mtxobject = Activator.CreateInstance(typeMtx);
// Getting classic ASP object context
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |