Project

General

Profile

« Previous | Next » 

Revision fb001aff

Added by Leszek Koltunski over 3 years ago

Plug two more memory leaks. It should be fine now.

View differences:

src/main/java/org/distorted/library/main/InternalMaster.java
19 19

  
20 20
package org.distorted.library.main;
21 21

  
22
import java.util.Set;
22
import java.util.ArrayList;
23 23

  
24 24
///////////////////////////////////////////////////////////////////////////////////////////////////
25 25
/**
......
48 48

  
49 49
  static boolean toDo()
50 50
    {
51
    Set<Slave> set = InternalStackFrameList.getSet();
52
    int numSlaves = set.size();
51
    Slave slave;
52
    ArrayList<Slave> list = InternalStackFrameList.getSet();
53
    int numSlaves = list.size();
53 54

  
54
    if( numSlaves>0 )
55
    try
55 56
      {
56
      for(Slave slave: set)
57
      for(int i=0; i<numSlaves; i++)
57 58
        {
58
 			  if( slave!=null ) slave.doWork();
59
 		    }
60
 		  return true;
59
        slave = list.remove(0);
60
        if( slave!=null ) slave.doWork();
61
        }
62
      }
63
    catch(IndexOutOfBoundsException ie)
64
      {
65
      // onDestroy must have been called, ignore
61 66
      }
62 67

  
63
    return false;
68
    return numSlaves>0;
64 69
    }
65 70

  
66 71
///////////////////////////////////////////////////////////////////////////////////////////////////
67 72

  
68 73
  public static void newSlave(Slave s)
69 74
    {
70
    InternalStackFrameList.getSet().add(s);
75
    ArrayList<Slave> list = InternalStackFrameList.getSet();
76
    int num = list.size();
77
    boolean found = false;
78
    Slave tmp;
79

  
80
    try
81
      {
82
      for(int i=0; i<num; i++)
83
        {
84
        tmp = list.get(i);
85

  
86
        if( tmp==s )
87
          {
88
          found = true;
89
          break;
90
          }
91
        }
92
      }
93
    catch(IndexOutOfBoundsException ie)
94
      {
95
      // onDestroy must have been called, ignore
96
      }
97

  
98
    if( !found ) list.add(s);
71 99
    }
72 100
  }

Also available in: Unified diff