Light memory singleton object.

Let's say you wanna build singleton but you want it to be kept in memory as long as someone is using it. This is possible if the instance static object is maintained via Soft or Weak reference. Here is how it is done:
class MySingleton
  private static Object objLock = new Object();
  private static WeakReference instance = null;
   * Gets the instance of this class.
   * @return MySingleton
  public static MySingleton getInstance()
    synchronized (objLock)
      if (instance == null || instance.get() == null)
        instance = new WeakReference(new MySingleton());
    return (MySingleton)instance.get();
}

Once you create the instance of the Sibgleton the GC
CANNOT clear it because of the static refernec to it.
If you don't know that fact first read more. I do understand what you want to do. I have been programming in Java for 10 years and have never heard about a person who has needed what you are trying to do, and I don't think that it is a good idea.
I can of course be 100% wrong on this since there are many different environments.
With the
weak or soft reference the GC can clear it anytime it
goes or needs memory (depending whether is weak or
soft). I know what weak a soft references do, but I don't understand why you want to use them. Your singleton will not be a singleton since instances will be created and destroyed. Creating your "heavy" object many times is worse than creating it one time.
That's the usefulness. It isn't useful. It's a singleton which isn't a singleton, and it's only good for read only data.
Let's say you have a
module that operates with huge objects and that
module is singleton. Once the application gets the
singleton it's created and never destroyed until the
app goes away. This way you ensure that this memory
is released after you don't use the singleton. Haven't you considered that you might create that huge object many many times with your design?
Kaj

Similar Messages

  • SingleTon object of WebServices (Please be specific as required and not be generic)

     // Singleton Object of viewservice
    private ViewService WorkListView = null;
    ViewServiceObjectCreation viewstrWorkListView =  ViewServiceObjectCreation.GetObject();
    // Object Creation
    public  class ViewServiceObjectCreation
            private static ViewServiceObjectCreation singleTonObject=null;
            private static readonly object lockingObject = new object();
            private ViewServiceObjectCreation()
            public static ViewServiceObjectCreation GetObject()
                if(singleTonObject == null)
                     lock (lockingObject)
                          if(singleTonObject == null)
                               singleTonObject = new ViewServiceObjectCreation();
                return singleTonObject;
    But this is not creating singleton object of webservice. How to create singleton object of webservice.
    Vivek

    Read my post again: Please describe your concrete problem which made you think you need a singelton.
    A singelton only works per domain. Thus it will not help in your sketched scenario. Cause it cannot prevent an user or administrator for starting another domain (a.k.a. process).
    In this case you should consider using a mutex, which is aquired when the web service is started and released when stopped.
    While singeltons are a cool pattern per se, they are one of those evil ones. They are often not a correct solution and much worse, the kill testability cause the represent a global state.

  • Singleton object in clustered enviornment

    Hi,
              In my web application which is deployed in clustered enviornment, I am facing problem for singleton object.
              I need to share object among all servers in the clustered.
              I am using weblogic server 9.2. I have tried its Singleton services, but it doesnt work as expected.
              what could be other solution to solve the problem?

    No. If you need this type of functionality, use Coherence.
              http://www.tangosol.com/coherence.jsp
              Peace,
              Cameron Purdy
              Tangosol, Inc.
              http://www.tangosol.com/coherence.jsp
              Tangosol Coherence: Clustered Replicated Cache for Weblogic
              "Ferruccio" <[email protected]> wrote in message
              news:[email protected]..
              > Hi,
              > I have a very basic question. In a WebLogic clustered
              > environment, is a Singleton replicated? In other words, if the
              > mySingleton on node A in a cluster is updated with a piece of data,
              > will this show in the mySingleton in node B?
              >
              > Thanks
              >
              > Ciao
              > Ferruccio
              

  • ThreadSafeLazyLoading of a Singleton Object

    Hi,
    Do anyone know the mechanism and necessity of this ThreadSafe Lazy loading of a singleton object?
    Thanks.

    I know the mechanism (I believe Enum is the popular choice these days).
    The necessity is dubious. Most people don't need lazy loading singletons, they just think it's a part of the Singleton pattern.

  • Multiple instances of a Singleton-Object by updaterule ?

    Hi folks,
    I'm trying to load > 1 Mio. records from an ODS into another InfoProvider. Every record gets some keyfigures out of a very very expensive table-join.
    I tried creating this join in an ABAP-Singleton-Object to reduce uploading-time.
    This object holds a private-static attribute 'instance' as a reference to a instance of the object and a public-static 'getInstance()'-method, which returns the 'instance'-value. This method is standard-Singleton-like designed.
    Then I created a process-chain with:
    - an ABAP-process, which calls the 'getInstance()'-method
      of this Singleton.
      At the first pass this method calls the constructor and
      after that a private method, which creates the join and
      holds the result in an internal table.
      So the constructor is empty.
    - after that the data should be transfered (by an Info-
      Package) from the ODS to the other InfoProvider. In some
      fields of the update-rule and in the startroutine of
      the rule the 'getInstance()'-method of the Singleton is
      been called and by this reference to the only (so I
      thought) instance some other methods should return a
      calculated value out of the join.
    So theory .... the startroutine is been called for multiple datapackages (no problem) --- but for every package in the startroutine the 'getInstance()'-method calls the constructor, so I get multiple instances of a Singleton.
    The time-gap between the package-calls is > 10 secs., so the static-attribute should been set immediately in the first pass of the 'getInstance()', since the constructor is empty.
        Any ideas ???
        Bye Ralf

    -/-

  • WTK Memory Monitor, "Objects" view - how to interpret percentages?

    In the WTK Memory Monitor "Objects" view, a table of objects and memory sizes is shown. When clicking on an entry, a tree view is shown on the right hand side. Each item in the tree view has a percentage number next to it - how do I interpret this? Is it relative to the "Live", "Total" or "Total size" value of the corresponding object? More specifically, is it a count or size percentage?

    In the WTK Memory Monitor "Objects" view, a table of objects and memory sizes is shown. When clicking on an entry, a tree view is shown on the right hand side. Each item in the tree view has a percentage number next to it - how do I interpret this? Is it relative to the "Live", "Total" or "Total size" value of the corresponding object? More specifically, is it a count or size percentage?

  • Linking a Light with a object

    How can I link the position of a light with a object?
    I've draw a mask on a 2D solid (Light-Spill) that appears to be the light (Light-Spot) hitting the floor (another 2D object (still photo)) and I want to be able to move the Light in the X dimension and have the Light-Spill follow with it. Now, I can do this by hand but I thought there would be a way to link the position properties by a behavior but none seem to be the correct thing. Can you not just add a "script" to a property like postion.Light-Spill=positon.Light-Spot
    TonyTony

    Hey Case,
    That did work. I had to make the Light-spill group a 3D group (then turned off lighting) and applied Match Move, dropped the Light-spot object in the source well. My Light-spill moved off the screen somewhere until I changed the transform pulldown from Attach to Mimic.
    A behavior (expression) that you can change various things on would still be a nice addition. I could see one called Link (in the Basic Motion group), that you apply, then drop a source object in the well, then have some pulldowns the allow you to pull from a particular property and then modify that information and apply to a particular property. Something like take scale from object A and effect rotation of object B. Also would be nice to see the expression in a text field somewhere. This why you could make you own.
    Probably throw this into the Motion user feedback.
    Thanks, your Special.
    TonyTony

  • How much memory an object consumed?

    Via making an internet lookup and writing some code, i made an implementation of
    how to calculate how much memory an object consumes. This is a tricky way.
    However, how can i achieve a better and direct way? Is there a tool for attaching
    to JVM and viewing the memory locations and contents of objects in memory?
    I wrote the tricky way to Javalobby and pasting the same explanation to here too.
    I must say that this tricky way does not belong to me, and i noted where i took
    the main inspiration etc. at the end.
    Because of the underlying structure Java does not let
    users to access and directly change the content of
    instances in memory. Users could not know how
    much memory is used for an object, like in C.
    However this tricky method lets them to know in an
    indirect way.
    To achieve how much memory is used for an object we must
    calculate the used memory before and after the object is
    created.
    MemoryUsage.java
    * User: Pinkman - Fuat Geleri
    * Date: Mar 20, 2005
    * Time: 11:13:50 AM
    * The class which makes the calculation job.
    * Calculating the difference of used memory
    * between calls
    * "start()", and "end()".
    * So if you initiate an object between those
    * calls you can get how much memory the object
    * consumed.
    * Initial inspration from
    * http://javaspecialists.co.za/archive/Issue029.html
    public class MemoryUsage {
         long usage;
         public void start(){
              garbageCollect();
              Runtime r=Runtime.getRuntime();
              usage=r.totalMemory()-r.freeMemory();
         public long end(){
              garbageCollect();
              Runtime r=Runtime.getRuntime();
              return (r.totalMemory()-r.freeMemory())-usage;
         public String memorySizeToString(long l){
              int MB=(int) (l/1048576);
              l=l-1048576*MB;
              int KB=(int) (l/1024);
              l=l-1024*KB;
              return new String(MB+"MB "+KB+"KB "+l+"BYTES");
         private void garbageCollect() {
              Runtime r=Runtime.getRuntime();
              r.gc();r.gc();r.gc();r.gc();r.gc();
              r.gc();r.gc();r.gc();r.gc();r.gc();
              r.gc();r.gc();r.gc();r.gc();r.gc();
    Therefore the first file MemoryUsage.java is coded.
    It simply calculates and stores the used memory when
    start() method is called. After generating some objects,
    the end() method is called to get the
    difference between memory usages, between the start()
    and end() method calls.
    SizeOf.java
    import javax.swing.tree.DefaultMutableTreeNode;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Random;
    * User: Pinkman - Fuat Geleri
    * Date: Mar 20, 2005
    * Time: 6:02:54 PM
    * Arbitrarily size of objects in JAVA..
    * An example of getting how much an
    * object consumed in memory.
    * Like
    *  primitives -> does not consume any
    *  arrays  -> consumes 16 bytes when empty
    *   ex: byte []a=new byte[0];
    *  list    -> consumes 80 byte when empty..
    *  references -> when did not initiated does
    * not consume any memory!.
    * Initial inspration from
    * http://javaspecialists.co.za/archive/Issue029.html
    public class SizeOf {
         MemoryUsage mu=new MemoryUsage();
         public static void main(String []args){
            SizeOf s=new SizeOf();
              s.sizeOfExample();
         //remove the comments in order to make the same checking by yourself..
         private void sizeOfExample() {
              mu.start();
              //byte []b=new byte[0];//<-byte array 16byte,each byte addition equals 1 byte!!
              //String s="How much memory is used?";//string consumes no byte!!
              //byte c=20; //<-consumes no memory!!
                    //Object o=new Object();//object consumes 8 bytes..
              //Object []oa=new Object[100];//<-object array consumes 16 byte! and each addition object 4 bytes!
                    //List list;//non initialized object consumes no memory!!..
              //Integer i=new Integer(1);//an integer object consumes 16 bytes!
              //List list=new ArrayList();//An array list consumes 80 bytes!.
              /*for(int i=0;i<10;i++){ //An array list + 10 integer consumes 240 bytes  :)
                   list.add(new Integer(i));
              Random r=new Random();
              byte []rand=new byte[1];
              int count=100000;
              List list=new ArrayList(count);
              for(int i=0;i<count;i++){
                   r.nextBytes(rand);
                   list.add(new String(rand));//empty string occupies no memory??
              DefaultMutableTreeNode root=new DefaultMutableTreeNode();//8 byte when single!.
              Random r=new Random();
              byte []rand=new byte[10];//when this is one and count is 1 million memory gets overfilled!..
              int count=500000;
              for(int i=0;i<count;i++){
                   r.nextBytes(rand);
                   root.add(new DefaultMutableTreeNode(new String(rand)));
              long l=mu.end();
              System.out.println(""+mu.memorySizeToString(l));
    An example usage can be found in the second file
    SizeOf.java. Simply remove the comments,"//", and execute
    to see how much memory used.
    For example:
    % Primitives does not consume any memory.
    % Non-initialized object references does not consume
    any memory.
    % Empty string and most of the small strings does not consume any memory.
    % Empty byte[] consumes 16 bytes.
    % Empty ArrayList consume 80 bytes.
    % An Integer object consumes 16 bytes.
    % Empty DefaultMutableTreeNode consumes 8 bytes..
    and so on.
    You can find the mentioned files in the attachments.
    I heard the idea of -how much memory is used- from
    Prof. Akif Eyler, and i got the main inspration from
    the site http://javaspecialists.co.za/archive/Issue029.html
    //sorry about my mistakes, and everything :)
    Thanks for your answers beforehand.

    Any good profiler will tell you.
    You can also code your own using jvmpi or jvmti.
    Also note that calling System.gc is a hint to the jvm it may or may not respect your wish.
    Test it with a few different gc algorithms and see what happens.
    /robo

  • Singleton Object With Anonymouse Methods

    I'm trying to create a singleton object using a GUI interface. The problem which I'm getting is that I can't find a way to create the object inside an .addActionListener() method while storing it for other .addActionListener() methods.
    CreditCard.java
       public class CreditCard {
           private static CreditCard uniqueInstance = null;
          final String creditCardNumber;
          String name;
          float creditLimit;
          float creditBalance;
           private CreditCard(String creditCardNumber,String name,float creditLimit) {
               this.creditCardNumber = creditCardNumber;
               this.name = name;
               this.creditLimit = creditLimit;
           public static CreditCard getInstance(String creditCardNumber,String name,float creditLimit)
               if (uniqueInstance == null)
                   uniqueInstance = new CreditCard (creditCardNumber, name, creditLimit);
               return uniqueInstance;
    Here's some code
    main class call
             CreditCard Student;
             JButton enterCardButton = new JButton("Edit Card");      
             enterCardButton.addActionListener(
                    new ActionListener() {
                       public void actionPerformed(ActionEvent ae) {
                         String cCNumber = creditCardNumberField.getText();
                         String cName = nameField.getText();
                         String cStringLimit = creditLimitField.getText();
                         float cLimit = Float.parseFloat(cStringLimit);
                         Student = CreditCard.getInstance(cCNumber, cName, cLimit);
             buttonPanel.add(enterCardButton);Of course the compiler error I get is that you must declare the CreditCard Student to be final. But if i make it final, I cannot create it in the method! I'm stuck :/

    You do need to call getInstance on a
    singleton. The compiler doesn't treat them specially.
    So, outside of the singleton itself you need
    something like
    String ccNumber =
    CreditCard.getInstance().getCreditCardNumber();(and it's probably best to define accessor methods
    for singleton fields).I actually do this for my other methods, thank you malcolmmc :). But the problem right now is the inablity to create the class using the ActionListener. I'm goign to Paste my whole code segment this time to try to provide a better picture.
    *          MAIN CLASS
    package Project2;
       import java.awt.BorderLayout;
       import java.awt.GridLayout;
       import java.awt.event.ActionEvent;
       import java.awt.event.ActionListener;
       import javax.swing.DefaultListModel;
       import javax.swing.JButton;
       import javax.swing.JFrame;
       import javax.swing.JLabel;
       import javax.swing.JList;
       import javax.swing.JPanel;
       import javax.swing.JScrollPane;
       import javax.swing.JTextField;
       import java.io.*;
       import java.lang.*;
       import java.util.*;
        public class Project2TestFrame {
          // public enum transactionType { LIMIT_CHANGE, CHARGE, PAYMENT}
           public static JFrame getTestFrame() {
             JFrame testFrame = new JFrame("Project 2 Tester");
          // Build the data portion of the frame
             final JTextField creditCardNumberField = new JTextField(15);
             final JTextField nameField = new JTextField(15);
             final JTextField creditLimitField = new JTextField(15);
             final JTextField chargeAmountField = new JTextField(15);
             JPanel dataPanel = new JPanel();
             dataPanel.setLayout(new GridLayout(4,2));
             dataPanel.add(new JLabel("Credit Card Number"));
             dataPanel.add(creditCardNumberField);
             dataPanel.add(new JLabel("Name"));
             dataPanel.add(nameField);
             dataPanel.add(new JLabel("Credit Limit"));
             dataPanel.add(creditLimitField);
             dataPanel.add(new JLabel("Charge Amount"));
             dataPanel.add(chargeAmountField);
             testFrame.add(dataPanel, BorderLayout.CENTER);
          // Add the buttons to the frame.  Note only the Exit button is
          // given here.  You should add other buttons.
             JPanel southPanel = new JPanel();
             southPanel.setLayout(new GridLayout(2,1));
             JPanel buttonPanel = new JPanel();
             southPanel.add(buttonPanel);
          // Add the messageField and
             String[] sarray = {"", "", "", "", ""};
             DefaultListModel dlm = new DefaultListModel();
             dlm.copyInto(sarray);
             final JList messageList = new JList(dlm);
             final JScrollPane jsp = new JScrollPane(messageList);
             southPanel.add(jsp);
             testFrame.add(southPanel, BorderLayout.SOUTH);
          // Add your buttons here.
             //Main Class Instance of CreditCard class.
             CreditCard Student;
             JButton enterCardButton = new JButton("Edit Card");
             enterCardButton.addActionListener(
                    new ActionListener() {
                       public void actionPerformed(ActionEvent ae) {
                         String cCNumber = creditCardNumberField.getText();
                         String cName = nameField.getText();
                         String cStringLimit = creditLimitField.getText();
                         float cLimit = Float.parseFloat(cStringLimit);
                         //***Compile Error** Needs to be final, but if final still complains
                         Student = CreditCard.getInstance(cCNumber, cName, cLimit);
             buttonPanel.add(enterCardButton);
             JButton chargeButton = new JButton("Charge Credit Card");
             chargeButton.addActionListener(
                    new ActionListener() {
                       public void actionPerformed(ActionEvent ae) {
                           String cStringCharge = chargeAmountField.getText();
                           float cAmount = Float.parseFloat(cStringCharge);
             buttonPanel.add(chargeButton);
             JButton paymentButton = new JButton("Payment");
             paymentButton.addActionListener(
                    new ActionListener() {
                       public void actionPerformed(ActionEvent ae) {
             buttonPanel.add(paymentButton);
             JButton dummyButton = new JButton("Transactions");
             buttonPanel.add(dummyButton);
             dummyButton.addActionListener(
                    new ActionListener() {
                       public void actionPerformed(ActionEvent ae) {
                         DefaultListModel messageData = (DefaultListModel)messageList.getModel();
                         messageData.clear();
                         messageData.addElement("String1");
                         messageData.addElement("String2");
                         messageData.addElement("String3");
             JButton exitButton = new JButton("Exit");
             buttonPanel.add(exitButton);
             exitButton.addActionListener(
                    new ActionListener() {
                       public void actionPerformed(ActionEvent ae) {
                         System.exit(0);
          // Finish and return data.
             return testFrame;
        * @param args
           public static void main(String[] args) {
             JFrame p2tf = getTestFrame();
             p2tf.pack();
             p2tf.setVisible(true);
        class Transaction {
          public enum transactionType { LIMIT_CHANGE, CHARGE, PAYMENT}
        //enum transactionType;
          int date;
          int amount;
           public Transaction(int date, int amount)
            //this.transactionType = transactionType;
             this.date = date;
             this.amount = amount;
    * CreditCard.java
    * Created on June 21, 2006, 9:27 AM
    * To change this template, choose Tools | Options and locate the template under
    * the Source Creation and Management node. Right-click the template and choose
    * Open. You can then make changes to the template in the Source Editor.
    package Project2;
       import java.io.*;
       import java.lang.*;
       import java.util.*;
       public class CreditCard {
           private static CreditCard uniqueInstance = null;
          final String creditCardNumber;
          String name;
          float creditLimit;
          float creditBalance;
          ArrayList<String> transactionHistory;
           private CreditCard(String creditCardNumber,String name,float creditLimit) {
               this.creditCardNumber = creditCardNumber;
               this.name = name;
               this.creditLimit = creditLimit;
           public static CreditCard getInstance(String creditCardNumber,String name,float creditLimit)
               if (uniqueInstance == null)
                   uniqueInstance = new CreditCard (creditCardNumber, name, creditLimit);
               return uniqueInstance;
           public void setName(String name)
             this.name = name;
           public String getName()
             return this.name;
           public String getCreditCardNumber()
             return this.creditCardNumber;
           public float getCreditLimit()
             return this.creditLimit;
           public void setCreditLimit(float creditLimit)
             this.creditLimit = creditLimit;
           public float getAvailableCredit()
             return this.creditBalance;
           public void addCharge(float chargeAmount)
            this.creditBalance -= chargeAmount;
           public void paymentReceived(float paymentAmount)
            this.creditBalance += paymentAmount;
        //public String[] getTransactions()
        //    return this.transactionHistory.toArray();
       class NumberOutOfBoundsException extends Exception {
        private int number;
        public NumberOutOfBoundsException() {
            number = 0;
        public NumberOutOfBoundsException(String Message) {
            super(Message);
        public NumberOutOfBoundsException(int number) {
            this.number = number;
        public NumberOutOfBoundsException(String Message, int number) {
            super(Message);
            this.number = number;
        public int getNumber() {
            return number;
    }

  • I have a memory leak, objective-c 2.0, and garbage collector...

    the code i am using is a modification of the code/problem found in "Cocoa with Objective-C", chapter 3.
    i have tried to use the objective-c 2.0 garbage collector methodology, using @property, @synthesize, etc. when i run the code as listed below i get a leaking message.
    [Session started at 2008-02-01 23:33:37 -0500.]
    2008-02-01 23:33:38.070 SongsFoundationTool[28876:10b] * _NSAutoreleaseNoPool(): Object 0x2040 of class NSCFString autoreleased with no pool in place - just leaking
    Stack: (0x96b10178 0x96a3e0f8)
    2008-02-01 23:33:38.075 SongsFoundationTool[28876:10b] Song 1: We Have Exposive
    2008-02-01 23:33:38.076 SongsFoundationTool[28876:10b] * _NSAutoreleaseNoPool(): Object 0x2060 of class NSCFString autoreleased with no pool in place - just leaking
    Stack: (0x96b10178 0x96a3e0f8)
    2008-02-01 23:33:38.078 SongsFoundationTool[28876:10b] Song 2: Loops of Fury
    The Debugger has exited with status 0.
    when i include the commented out section, in the implementation file section, the description method, and use song1 and song2, in main, instead of song1.name and song2.name the program seems to run fine.
    The Debugger has exited with status 0.
    [Session started at 2008-02-01 23:38:24 -0500.]
    2008-02-01 23:38:24.375 SongsFoundationTool[28936:10b] Song 1: We Have Exposive
    2008-02-01 23:38:24.379 SongsFoundationTool[28936:10b] Song 2: Loops of Fury
    The Debugger has exited with status 0.
    please help me understand what's happening here.
    also, why was it necessary to use
    @property(copy, readwrite) NSString *name;
    @property(copy, readwrite) NSString *artist;
    instead of
    @property(readwrite) NSString *name;
    @property(readwrite) NSString *artist;
    thanks everyone, the code is below.
    // ....................... header file ...............
    #import <Cocoa/Cocoa.h>
    @interface Song : NSObject {
    NSString *name;
    NSString *artist;
    @property(copy, readwrite) NSString *name;
    @property(copy, readwrite) NSString *artist;
    @end
    //.................... the implementation file ..................
    #import "Song.h"
    @implementation Song
    @synthesize name;
    @synthesize artist;
    -(NSString *) description
    return [ self name ];
    @end
    //................................ main............................
    #import <Foundation/Foundation.h>
    #import "Song.h"
    int main (int argc, const char * argv[]) {
    Song *song1 = [ [ Song alloc ] init ];
    song1.name= @"We Have Exposive" ;
    [ song1 setArtist: @"The Future Sound Of Londown" ];
    Song *song2 = [ [ Song alloc ] init ];
    [ song2 setName: @"Loops of Fury" ];
    [ song2 setArtist: @"The Chemical Brothers" ];
    // Display Object
    NSLog( @"Song 1: %@", song1.name );
    NSLog( @"Song 2: %@", song2.name );
    // include statements below if -description method is uncommented
    // then comment out the two statements above. no memory leak if the code
    // is used from the statements below and - description is not commented out and
    // the two NSLog statements above are commented out.
    NSLog( @"Song 1: %@", song1 );
    NSLog( @"Song 2: %@", song2 );
    return 0;
    }

    Normally, your main only has a call to NSApplicationMain(). If you aren't doing a traditional MacOS X application, you will still want at least NSApplicationLoad() to get enough of the runtime to avoid those messages.
    I don't know for sure about the syntax of Objective-C 2.0. That stuff is all new. What error message are you getting that indicated that (copy, readwrite) is required? Could you provide a link to the actual example source? I did a quick check and assign and readwrite are the defaults. It is possible that readwrite by itself makes no sense. But I'm just guessing.

  • Red Light with Authorization Object in PFCG

    Hello All - I have a question with authorization objects, there are three roles with red lights 'ON' in authorization object screen in our PRD. However users who are using these roles have no auth issues, standard procedure is to make all lights green in PFCG by maintaining these auth objects.
    Big question is "what is the down fall by leaving these objects RED, I need to support my theory when I say all lights green with auth objects.
    Why best practise says maintain all lights to green?
    Please suggest, appreciate your suggestions.
    Thanks.
    Edited by: AJ on May 12, 2009 9:44 PM

    Hi,
    > "What will be the difference between leaving that red lights 'ON' vs "disabling" these red objects? (I am bit confused on this).
    Red Object: As you know that authorization Objects comprises of Authorization fields. There are certain fields, which are known as "Organization Level" fields and need to be maintained Centrally. If you miss this fields, then the traffic light icon is RED. For all other authorization fields, light will be Yellow if you miss any blank field to maintain. During check, these fields will provide missing authorization (but you may not get error if same object is present in the role with all fields maintained status).
    Disabled Object: If you make any Object Disable, then during check, this Object will not be treated for checking Authorizations. But profile generator will keep this in mind, so you don't get Standard Objects repeatedly (if already present in Deactivated status also) whenever you go to "..Merge with New Data".
    You all other questions are very nicely answered already.
    Regards,
    Dipanjan

  • When does java deallocate memory for objects;

    um i'm working on a midp application that is very memory consuming. i would like to optimise it and make it just the oposite of what it is. now i would like to know when does java dellocate memory for an object, is it when it can find no more references to that object? or some other time, well i know its not when it can find no more references to that object because i've already tried that.
    or to make things simpler is there any explicit way to make java deallocate memory for a specific object, like if i have a thread, which is executing a while loop, and i want java to end the thread and free its memory. is there any way to do this?

    I happen to have quite some J2ME experience and it's not overly wise to count on extensive garbage collection. The garbage collector in limited device VMs isnt as advanced as it's big brothers. Try to avoid excessive object allocation and reuse instances whenever possible.
    As for garbage collection, objects will be garbage collected if they can no longer be reached by any of the active application threads and if the garbage collectors deems it necessary to collect garbage, which will probably be when free heap memory becomes sparse or when there's some idle time in your application.

  • JVM reserves additional memory after object creation

    Hi everybody,
    i have a problem with starting the JVM from inside a C++application. Starting the VM with JNI_CreateJavaVM works as aspected. When creating the first object it seems like the JVM reserves additional memory (outside the heap). Here is a little c++ test case:
    /* Compile/Link: cl -MT -Zi -EHsc -I%JAVA_HOME%\include jvmtest0.cxx user32.lib %JAVA_HOME%\lib\jvm.lib */
    #include "windows.h"
    #include <string>
    #include <jni.h>
    int availMem () {
         int i,j;
         void* v[2048];
         for (i=0;i<2048;i++) {
              if ((v=malloc(1024*1024))==0) break;
         for (j=0;j<i;j++) free(v[j]);
         return i;
    int WINAPI WinMain(HINSTANCE hinst,HINSTANCE hprev,LPSTR cmd,int show)
         int i1=availMem();
         JavaVMInitArgs arg;
         JavaVMOption opt[1];
         arg.version=JNI_VERSION_1_2;
         arg.ignoreUnrecognized=JNI_TRUE;
         opt[0].optionString="-Xmx256m";
         arg.nOptions=1;
         arg.options=opt;
         JavaVM* vm;
         JNIEnv* en;
         if (JNI_CreateJavaVM(&vm,(void**)&en,&arg)<0) {
              MessageBox(NULL,"Error CreateJavaVM","jvm-Test",MB_OK);
              return (1);
         jclass clFrame=en->FindClass("Ljavax/swing/JFrame;");
         if (clFrame==0) {
              MessageBox(NULL,"Error FindClass","jvm-Test",MB_OK);
              return (1);
         jmethodID methodID=en->GetMethodID(clFrame,"<init>","(Ljava/lang/String;)V");
         if (methodID==0) {
              MessageBox(NULL,"Error GetMethodID","jvm-Test",MB_OK);
              return (1);
         int i2=availMem();
         jobject window=en->NewObject(clFrame,methodID,en->NewStringUTF("Test"));
         if (window==0) {
              MessageBox(NULL,"Error NewObject","jvm-Test",MB_OK);
              return (1);
         int i3=availMem();
         char o[256];
         sprintf_s(o,"Available memory:\nStart: %d MB\nAfter CreateJavaVM: %d MB\nAfter JFrame: %d MB",i1,i2,i3);
         MessageBox(NULL,o,"jvm-Test",MB_OK);
         return (0);
    I'am running on Windows XP with JDK 1.5.0_02 and get the following result:
    Start: 1906 MB
    After CreateJavaVM: 1558 MB
    After JFrame: 1312 MB
    I would expect that the available memory after constructing the Java object is similar to the available memory after creating the JVM. On Linux it is.
    Thanks

    a=null
    MyClass a = new MyClass();
    is the same as
    MyClass a = new MyClass();
    because after MyClass a = new MyClass(), doesn't point to a possible old instance but to a new instance of MyClass.
    I guess, the problem is in some other data structure you build. perhaps the vector that contains lots of/big other objects? does any other class point to these objects too? remember: the garbage collector does clean up only unused memory, i.e. objects that are not referenced by any other objects that are valid (i.e. are referenced by the main thread or objects of the main thread).

  • How to create more kinds of singleton objects?

    Hello,
    in my application I need to create more objects. Every object does during its creation same actions (they differ only in one parameter) and add some own methods.
    These all objects should behave as a singleton pattern.
    Could you help me (different design pattern) how to achieve this?
    Thank you.

    I have such slightly modified Multiton pattern class.
    Now I want create a method that returns database server IP address from database setting type - try to tell me (exactly) how to write this method.
    public class Setting {
         public enum Type {
              database, application, mail
         private static final Map<Object, Setting> instances = new HashMap<Object, Setting>();
         protected PropertiesFile file = null;
         private Setting(Setting.Type key) throws IOException {
              file = new PropertiesFile(key.toString() + ".properties");
         public static Setting getDatabase() throws IOException {
              return Setting.getInstance(Setting.Type.database);
         public static Setting getApplication() throws IOException {
              return Setting.getInstance(Setting.Type.application);
         public static Setting getMail() throws IOException {
              return Setting.getInstance(Setting.Type.mail);
         private static Setting getInstance(Setting.Type key) throws IOException {
              Setting instance = instances.get(key);
              if (instance == null) {
                   instance = new Setting(key);
                   instances.put(key, instance);
              return instance;
    }

  • Reading in memory big objects

    Hi
    how to read realy big objects (300-500 MB) in memory part by part (better say dynamicaly) - I mean, that you dont have ANY POSSIBILITY read him fully.
    Maby it should be buffering, or not - I dont know.
    THANK YOU

    Out of curiosity, how long would it take someone
    to read 500 MB of text?I slaved on the answer, and not so much as a thank
    you, go figure. : )
    hey drlazlojamf, just out of curiosity, how long
    would it take someone
    to thank someone else for satiating their incessant
    curiosity?Well, let me get out my slide rule. Hmmm... 300 cubits per hogshead...
    About now! Thank you TP, you have enlightened all our lives.
    The OP seems unrepentant; I thought he'd come back with at least
    a "but my manager says its a design requirement". But I guess the
    shame was too great. And for that we give thanks.

Maybe you are looking for