How can we destroy the instance of a singleton object?

I think by writing a method like getInstance and making null in that method will not the correct answer of this. Can someone tell me what should I do.

why do you need to destroy the singleton?
normally..it should live for the duration of the application.
most singleton i've worked with are used by sevarals different classes.
if you're singleton use by only one class...refactor your code to make the singleton an inner class. so the singleton will be destroy when that class is no longer references 9and gc kick in)
if the singleton is share among several class...you can have a destroy method...like destroyInstance() where you null the singleton. keep in mind about synchronization of the method as well as the instance ... example createInstance() and destroyInstance() get call at the same time.. Also, make sure you have condition to check to determine if your singleton class is null or not
example
MySingleton s = MySingleton.createInstance();
Object obj = s.getData(); // what happen when another thread call MySingleton.destroyInstance() you're s.getData would result in NullPointerException
so..it's not wise to destroy a singleton.
I think what is better for your app is an Object Pool that create new instance (if none exist) and hand it out to any requester...and recycle the object...or null it after use)

Similar Messages

  • How can I make the Instance name the same as the name of the Movie clip in an animation.

    Hi, I am an animator for a small game project and I have this really big problem. Even though I used flash for animation for a long time I am a newbie when it comes to something technical. I just received a request to make every movie clip that I use  to have a consistent <Instance name> in every frame of the animation. Only if they told me this earlier... Is there an easier way to make the <Instance name> the same as the name of the Movie clip used other than manually entering it. I have 16 characters with 12 body parts with 20 animations each with about 6-7 frames for each body part it will take me months and nightmares evey night to enter everything by hand. Please help me keep my sanity!
    I'm not sure if I explain correctly, so here is a picture:
    Thank you!

    Thank you for the fast answer! I found this video on jsfl functionality that deals with a similar problem, I am not a coder so it will take me some time to figure it out, but when I do I will probably post the answer here. Here is the video:

  • How can I change the color of a single object?

    I have a bright orange barrel in a video of mine and I want to change it to a cooler color without changing the rest of the scene? How can I do this?

    Hi
    In FCP, under the help menu, choose Final Cut Pro Help.
    When it opens, search for " Using the Limit Effect Controls of the Color Corrector Filter to Change a Specific Color".
    MtD

  • How can i view the angle of a rotated object?

    ok, so i have rotated an object manually (not by entering a numberic value), and i now want to rotate something by exactly the same degree. how can i do this?
    am working in AI CS3.
    many thanks.

    If by "manually" you mean you dragged with the Rotate Tool, and the rotation you want to replicate is the one you just made, you can just doubleClick the Rotate Tool. The last-used rotation value will be recorded there, even if the rotation was done manually by dragging the tool.
    If by "manually" you mean you dragged with the black pointer just outside the bounding box corner, then you can repeat the rotation on another object by selecting the other object and typing Ctrl D (Transform Again). That will rotate the newly selected object the same amount, but also about the same center. So you may have to reposition it.
    JET

  • How can we contrrol the focus of an form Object  from the Managed bean??

    I am getting the following script error...
    Can't move the focus to the control because it is invisible or not enabled or of the type that does not accept the focus...
    I have a button whose action is mapped to a function in the Managed bean.
    In the managed bean
    I am making the button Invisible along with some other components.
    Can any one help me out....

    @BalusC
    You were proposing the following solution in other thread..
    <html>
    <head>
    </head>
    <body>
    <f:verbatim>
    <script>
    setFocus('</f:verbatim><h:outputText value="#{myBean.focusId}" /><f:verbatim>');
    </script>
    </f:verbatim>
    </body>
    </html>
    But it is giving the following error
    javax.faces.FacesException: org.apache.jasper.JasperException: /EducationDetails.jsp(97,29) The element type "script" must be terminated by the matching end-tag "</script>".

  • How can I find the instances of a subvi programmat​ically

    When one subvi appears for several times in the blockdiagramm, who can I get a ID number for every instance of the subvi?
    When I right-click on the subvi -> "Find all instances" then I get how often the subvi appears on the blockdiagramm but i need the information programmatically.
    Thanks for helping!
    Mathias

    LabVIEW won't let you save "DAsst_mxwScript_Get SubVI Refnums.vi" for a previous version of LabVIEW since its a "toolkit vi" if you try to do this with the "Save with Options" feature. However, LabVIEW *will* let you invoke the "Save for Previous" VI server method on toolkit VIs :-)
    Attached are the VIs saved in LV 6.1
    -Jim
    Attachments:
    Find_All_SubVIs_by_Name-6.1.zip ‏39 KB

  • I lost my Mac book air, how can I destroy the data?

    Appreciate for any comment and solution

    I believe if you have Find my PC/Phone/Ipad enabled thru Icloud you can quickly find it and by clicking on  the right hand blue arrow next to it (as displayed on a map) you get the option to lock it down or trash it. I may be wrong...but I think thats right.
    Rgds
    Rod
    Perth

  • How can I automate the threshold for a moving object whose light intensity changes for each frame.

    I'm using the PCI-1408 and I have this video where an object's shape and color intensity changes for each frame. I want to do a pixel count of that object verses the background (the background also changes color) for each frame. I'm guessing that I need an automatic threshold, but I really have no idea of how to implement this. Any ideas, anyone?

    Hopefully there is a clear distinction between the background and the object.
    You can use IMAQ AutoBThreshold to determine the threshold level for an image. You can select from a variety of methods for determining a binary threshold level. Route the "Threshold Data" output along with your image to IMAQ MultiThreshold, which will quickly apply the threshold to your image. Display the results using WindDraw and the Binary palette (from IMAQ GetPalette).
    This should run close to real-time. Binary thresholding is a fairly fast operation. You will probably end up processing every other image, which is close enough for most projects.
    Bruce
    Bruce Ammons
    Ammons Engineering

  • How Can I change the color in a 3d object?

    Hello.
    I have received a 3dPDF, on which several buildings are created in 3d. Is it possible afterwards to change the color of the buildings in Acrobat X Pro? Or do I need the plugin "Tetra4D"?
    Thank you for your help.
    Greeting
    Sascha

    You can change the color of model parts dynamically at runtime using JavaScript, but there is no way to change them within the embedded model itself.

  • How can I get the container of a button after the button is clicked?

    I have two components:
    public class A extends JPanel implements ActionListener {
        public A() {
        public void actionPerformed(ActionEvent e) {
            String command = e.getActionCommand();
            // here need to know the instance of B to execute it's process()
            // but I can only know the button jb in B via the following code:
            JButton myjb = (JButton)(e.getSource());
    public class B extends JPanel {
        public ContainerInfoInput(ActionListener al) {
            JButton jb = new JButton("OK");
            jb.setActionCommand("B.ok");
            jb.addActionListener(al);
        public process() {
    public class Main {
        A a = new A();
        B b = new B(a);
    }How can I get the instance of B in which the button is clicked?
    Thank you

    I think it's a defect of the listener mechanism. Under the present circumstance, I must do it like the following:
    I must use another class M as a bridge:
    class A {
        public A() { }   
        public processA (String info ){}
    class B{
        public B(ActionListener al) {       
            JButton jb = new JButton("OK");       
            jb.setActionCommand("B.ok");      
            jb.addActionListener(al);  
       public String processB () {    }
    class M implements ActionListener  {
        public M() {
            A a = new A();
            B b = new B(this);
        public void actionPerformed(ActionEvent e) {
            String command = e.getActionCommand();
            if(command.equals("B.ok")) {
                String information =b.processB();
                a.processA(information);
    }Why not just use A to listen B and obtain instance of B through the ActionEvent?
    Anyone know a solution about it?

  • How can I get the X and Y coordinates of an object in Xcode, ApplescriptObjc?

    How can I get the value of a specified object's X and Y coordinates in Xcode, using ApplescriptObjc? I'm hoping for something like:
    myObject's currentPosition()
    // Which would return {150, 100} for the X and Y of that object.

    Actually this is straight from basic physics
    Assuming that the x and y values you get using that AppleScript/Objective-C code is accurate, to move the object you would do
    set x to x + dx * speed
    set y to y + dx * speed
    with dx and dy being an integer with a value of -1 or 1 which indicates the direction the object is moving. Remember the origin in OS X is the middle of the frame or screen with positive x and y values moving to the upper right quadrant, and negative x and y values moving to the lower left. Your basic Cartesian coordinate system. Speed is also an interger and models the speed of the object.
    Once you've set x and y to their new values you would write  them back to the object.
    This is so I can find how much distance (in pixels) is being travelled when I animate an object to move from one position to another, to apply it to my desired velocity (of pixels per second), to find out how long the object should take to move.
    This part has got me stumped.
    To make an object move you need to change its x and y coordinates. To get smooth animation you need to change them on a regular schedule at a rate fast enough to avoid jerky motion. Given the refresh rate of most monitors and other factors a rate of 60 times per second gives good results. Between each tick of the clock you change the x and y coordinates by some amount, the size of the amount will model speed. Add a small change and the object moves slowly, add a big amount and the object moves quickly. Keep the amount of change constant and the object will move at a constant speed. Increase (or decrease) the amount of change between each tick and the object will accelerate (or decelerate)

  • How can we lock the table?? how can we lock the record

    Hi
    how can we lock the complete table?? how can we lock the record ?/
    Thanks
    Rama

    Lock objects are used to lock the database table while making the modifications on the database table.
    you can create your own lock objects using SE11.
    if you create lock objects on any table system will create two function modules.
    1.ENQUEUE....
    2.DEQUEUE.....
    first one is used to lock the table
    second one used to removing lock on the table.
    lock Table
    CALL FUNCTION 'ENQUEUE_E_TABLE'
    EXPORTING
    tabname = table_name
    EXCEPTIONS
    foreign_lock = 1
    system_failure = 2
    OTHERS = 3.
    Unlock Table
    CALL FUNCTION 'DEQUEUE_E_TABLE'
    EXPORTING
    tabname = table_name
    check this link :
    http://help.sap.com/saphelp_40b/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm
    _SCOPE = 1: The lock is not sent to the update program. The lock is removed when the transaction is ended.
    _SCOPE = 2: The lock is sent to the update program. The update program is responsible for removing the lock. The dialog program which requested the lock no longer has an influence on the lock behavior. This is the standard setting for the ENQUEUE function module.
    _SCOPE = 3: The lock
    Re: lock objects
    Reward if this helps.

  • How do I remove the white background of an object in cs6

    How can I remove the white background of an object in CS6

    I went into YouTube as well, and indeed: It didn't remove the white background.
    Then I went into Photoshop and was surprised: It was able to remove the white background by just playing around with the Magic Wand Tool. I also went into other programmes similar to Photoshop and was excited that there were connatural ways to remove the white background. Finally, I went into Illustrator and observed that the clipping path route worked. Even in CS6.
    Not sure why it didn't work for you.

  • How can I change the settings of all instances of a particular effect?

    I've applied the same color correction effect to a lot of clips in the timeline. Now I want to fine tune the color correction (same setting for all clips still). How can I change the setting of all instances of the color correction effect without going into each clip manually?
    Looking forward to your thoughts on this!! Go on and save my cold winter editing day ...

    I was first hoping for File> New > Adjustment layer, but it's always greyed out. I thought that would create an adjustment layer, maybe I'm misunderstanding something? Anyway, if I create a black video stump and then right click it and choose "Adjustment layer", it will turn into one, and everything works as it should with that. If the black video become adjustment layer is placed on a video track atop my video, and I add for example color correction to it, it will be applied to the videos below.

  • How can I know the number of ejb instances

    Hi all,
    We need to know how can we get the number of ejb instances (entity and session) while the application is running.
    We have a memory leak, so we need to know the amount opf memory used.
    Please, it´s quite urgent, can anybody help us? It seems like an Oracle 9ias 903 bug.
    Thanks

    I'm not sure if this will help you, but the "Spy" application that comes with OC4J stand-alone may help. I suggest you search this forum's archives for the words "Spy" and "AggreSpy".
    Good Luck,
    Avi.

Maybe you are looking for