File tree 2 files changed +17
-0
lines changed
2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,7 @@ public function validate()
136
136
foreach ($ this ->validators as $ validate )
137
137
$ this ->$ validate ($ reflection ->getStaticPropertyValue ($ validate ));
138
138
139
+ $ this ->record ->clear_model ();
139
140
return $ this ->record ;
140
141
}
141
142
@@ -643,6 +644,15 @@ public function __construct(Model $model)
643
644
$ this ->model = $ model ;
644
645
}
645
646
647
+ /**
648
+ * Nulls $model so we don't get pesky circular references. $model is only needed during the
649
+ * validation process and so can be safely cleared once that is done.
650
+ */
651
+ public function clear_model ()
652
+ {
653
+ $ this ->model = null ;
654
+ }
655
+
646
656
/**
647
657
* Add an error message.
648
658
*
Original file line number Diff line number Diff line change @@ -114,5 +114,12 @@ public function test_get_validation_rules()
114
114
$ validators = BookValidations::first ()->get_validation_rules ();
115
115
$ this ->assert_true (in_array (array ('validator ' => 'validates_presence_of ' ),$ validators ['name ' ]));
116
116
}
117
+
118
+ public function test_model_is_nulled_out_to_prevent_memory_leak ()
119
+ {
120
+ $ book = new BookValidations ();
121
+ $ book ->is_valid ();
122
+ $ this ->assert_true (strpos (serialize ($ book ->errors ),'model";N; ' ) !== false );
123
+ }
117
124
};
118
125
?>
You can’t perform that action at this time.
0 commit comments