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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:57:20+00:00 2026-06-07T23:57:20+00:00

Suppose I’m creating a class called Hitchhiker. package hi.my.name.is { public function Hitchhiker():void {

  • 0

Suppose I’m creating a class called Hitchhiker.

package hi.my.name.is {
    public function Hitchhiker():void {
        // ...
    }

    public function nullify():void {
        this = null;
    }
}

And then it gives me an error:

Error: Cannot assign to a non-reference value.

What the heck? I though you can set an instance to null, like:

var hitchhiker:Hitchhiker = new Hitchhiker();
hitchhiker = null;

Why can’t I do this in the class? I’m intending to remove all event listeners by setting the reference to weak reference, then nullify the instance to remove them all. Why can’t I?

Anybody help me?

  • 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-07T23:57:23+00:00Added an answer on June 7, 2026 at 11:57 pm

    Where have you defined the class in the first place? This is how you define the class:

    package xyz {
    
        public class Hitchhiker {
    
            public function Hitchhiker():void {
    
            }
    
            public function nullify():void {
                this = null;
            }
        }
    }
    

    Besides your error comes here: this = null;


    Basically the error means you cannot nullify the object from inside the instance of the class, you can only nullify the object from outside, which you are already doing.

    So remove the function ‘nullify’.


    Example of using dispatchEvent:

    public function nullify():void { 
    
                dispatchEvent(new Event("destroyMe")); 
    }
    

    You can listen to it by:

    obj.addEventListener("destroyMe", destroyObject);
    
    function destroyObject(event:Event):void { 
    
                // set your object to null here 
    }
    

    Or a better way could be to use Arrays to keep track of the objects created.

    But I am still not sure why you don’t want GC to handle this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose i have this class: class Foo Public Property a() As Integer Private _l
Suppose one has this code: class MyClass { public: MyClass(int foo) : foo(foo){} private:
Suppose I have a simple model, such as Record: @Model public class Record {
Suppose the following constructor: class Needed { public: Needed () {} Needed (const char
Suppose I have a custom object set up in a class similar to this.
Suppose I have a table like: Tab(MyDate datetime null, MyIs bit null, ...) Then
Suppose I define an export in AssemblyA: [Export(typeof(Foo))] public class Foo { ... }
Suppose I have this code: class Num: def __init__(self,num): self.n = num def getn(self):
Suppose you have the following object hierarchy: class Vehicle { public: virtual ~Vehicle() {}
Suppose I have a vertical menu that is coded like this: <ul class=sub-menu> <li

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.