Everyone has a constitution right to reasonable bail. That does not mean everyone who is arrested gets released, but it does mean that people should not be held in custody waiting for a criminal trial without a good reason.
Under the Criminal Code people can be held pending a criminal trial because:
There is a legitimate concern they won't show up for trial if released;
There is reason to believe they will commit offences before trial; or
The perception of justice requires they be held before trial.
If someone is taken arrested and held for court, the Crown prosecutor can oppose that person's release. In that situation a bail hearing is held.
In a bail hearing (sometimes called a show cause hearing or a judicial interim release hearing) a Justice of the Peace decides whether to release the accused person before the case is dealt with in court.
The Justice of the Peace will detain the accused only if there is a ground to - one or more of the three bases described above.
At the bail hearing, the Crown prosecutor and the defence lawyer summarize the evidence against the accused. The Justiceh of the Peace will consider such matters as whether the accused person has a criminal record or charges pending, the seriousness of the charge, and whether it involves any violence.
If the Justice of the Peace decides to release the accused person, there may be conditions attached. These might include requiring the accused to report in to authorities; remain in the jurisdiction; not communicate in any way with any complainant or witness; and abide by other conditions considered necessary for the safety and security of complainants or witnesses. If the alleged offence involved violence, a weapon or criminal harassment, the Justice of the Peace must also add a condition prohibiting the accused from possessing any weapons.