I guess the problem is not that FormState grows. I think it's the session that grows. The thing is - as you go on doing postbacks or opening new pages, a new FormState is created. This FormState is saved in your PHP session (you are using QSessionFormStateHandler). At one point of time, the total size of all FormStates can get so big that PHP will not be able to handle that in session data. This happens because PHP has a setting which limits the amount of memory each script-run/request will consume (and that is a good thing).
Most of the times, PHP will complain about it by reporting that memory was exhausted. The reason this happens is: when you run/call a script, following things happen:
- PHP loads the user session information initially.
- PHP proceeds with Script execution.
- PHP executes the commands and goes on allocating more memory if needed.
- PHP ends execution
In your case, session data will keep on growing till it starts consuming enough memory that PHP cannot work allocate new variables within the set memory constraints (step 3 fails).
You have two solutions:
Use another FormStateHandler. I would recommend using QDbBackedFormStateHandler to keep file system clean. Using another FormStateHandler makes sure that your session data is separate from your FormState data and all FormStates are saved individually (either in file or as a separate DB entry) and ensures that useless FormStates are not collected in your session.
Increase PHP's per-script memory limit. This solution is not recommended and you should use it only as a temporary solution.
Also, there might be cases where you have declared a temporary variable in your form or one of the child controls which goes on growing. Consider this:
<?php
// We are inside the definition of a control/panel/form
$this->arrObj_TempEntries = array();
// ... using the above variable somewhere inside an event handler:
public function btnRefreshHandler($strFormId, $strControlId, $strParameter) {
// Assume $arrObj_NewEntries is already populated with some objects
foreach($arrObj_NewEntries as $objNewEntry){
array_push($this->arrObj_TempEntries, $objNewEntry);
}
}
// ... rest of the stuff
?>
In this case, the value of $this->arrObj_TempEntries
will go on increasing because the old entries are not being cleared out and result in a very huge FormState and that will eventually crash the page. If the objects are controls, it is an even bigger issue.
I hope this helps.