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

  • SEARCH
  • Home
  • 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 8483303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:03:51+00:00 2026-06-10T20:03:51+00:00

private class Node { Item name; Node next; public void deleteObject() { this =

  • 0
private class Node
{
    Item name;
    Node next;

    public void deleteObject()
    {
        this = null;
    }
}

Is it possible to delete object inside class? I am trying to do above, but it gives an error, that left-side should be a variable. Node is inner class. Thank you.

Edit:
var1 and var2 has reference to the object of this class, when I delete var1 by doing var1 = null, I want that var2 would be deleted too.

  • 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-10T20:03:53+00:00Added an answer on June 10, 2026 at 8:03 pm

    No, that’s not possible. Neither is it necessary.

    The object will be eligible for garbage collection (effectively deallocated) as soon as it is not reachable from one of the root objects. Basically self-references doesn’t matter.

    Just make sure you never store references to objects which you won’t use any more and the rest will be handled by the garbage collector.

    Regarding your edit:

    Edit: var1 and var2 has reference to the object of this class, when I delete var1 by doing var1 = null, I want that var2 would be deleted too.

    You can’t force another object to drop its reference. You have to explicitly tell that other object to do so. For instance, if you’re implementing a linked list (as it looks like in your example), I would suggest you add a prev reference and do something like:

    if (prev != null)
        prev.setNext(next);  // make prev discard its reference to me (this).
    
    if (next != null)
        next.setPrev(prev);  // make next discard its reference to me (this).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in this short code: class X { private: class Y { public: typedef void
I have this class : public class Stack { private class Node { String
public class Node { private Node nextNode; @Override public int hashCode() { //How to
Well, I have the following class definitions: private ObservableCollection<Node> _Nodes; public ObservableCollection<Node> Nodes {
class B{ private: void DoSomething(); } class W{ private: class D: public B{ }
private class CompAdvertisements : IComparer<Advertisements> { private string OrderBy { get; set; } public
Given the following types private class MyTestDummyClassValidationDef : ValidationDef<MyTestDummyClass> { ... } public class
i have a class extends asynctask private class taskMK extends AsyncTask<Void,Void,JSONObject>{ String url; JSONObject
I have the following class: private class NodeTemp { public string Content; public NodeTemp
class Newstring { public: Newstring(); void inputChar ( char); void display (); int length

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.